直接上代码
1.创建ServiceUtils工具类 将要用到的通过@Autowired注解到里面
package com.deao.app.socket.netty.server.service.impl;
import com.deao.app.socket.netty.server.service.MessageService;
import com.deao.app.socket.netty.server.service.SocketGasExamArrangeManageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
@Component
public class ServiceUtils {
@Autowired
public SocketGasExamArrangeManageService socketGasExamArrangeManageService;
@Autowired
public MessageService messageService;
public static ServiceUtils serviceUtils;
@PostConstruct
public void init() {
serviceUtils = this;
}
}
其他地方使用
public static void main(String[] args) {
serviceUtils.socketGasExamArrangeManageService.selectGasExamArrangeManageByStudentId(studentId);
serviceUtils.messageService.message(null, request, account, null, true);
}