Spring Boot在自定义类中调用service层等Spring其他层
@Component
public class ServerHandler extends IoHandlerAdapter {
@Autowired
protected HealthDataService healthDataService;
private static ServerHandler serverHandler ;
@PostConstruct //通过@PostConstruct实现初始化bean之前进行的操作
public void init() {
serverHandler = this;
serverHandler.healthDataService = this.healthDataService;
// 初使化时将已静态化的testService实例化
}
//测试调用
public void test(){
serverHandler .healthDataService.<你的service层方法>;
}