Springboot 真是不方便,在一个不是 @Controler 或者 @Service 的类中用 @Autowired 注入一个类,报空指针异常。
网上搜到的可用的解决方法:blog.csdn.net/georgeshaw1/article/details/74943089
需要注意这种写法,在调用注入类时的写法是:serverHandler.healthDataService.findById( id );
类对象.xxxxService.findById( id ); 这种写法看着很怪异,不过管用。
----------------------------------------------------------
经测试,在启动类上使用注解 @ComponentScan(basePackages = { "com.xxx" }) 也不能解决这个问题。