Springboot依赖注入 Service类中使用静态变量
@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层方法>; } }
引自 https://blog.csdn.net/georgeshaw1/article/details/74943089