springboot autowire 注入类 是空指针 null pointer

Springboot 真是变态,用 @Autowired 注入一个类,报空指针异常。

网上搜到的可用的解决方法:blog.csdn.net/georgeshaw1/article/details/74943089

需要注意这种写法,在调用注入类时的写法:serverHandler.healthDataService.findById( id );

类对象.xxxxService.findById( id );

这种写法看着很怪异,不过管用。

----------------------------------------------------------

经测试,在启动类上使用注解 @ComponentScan(basePackages = { "com.xxx" }) 也不能解决这个问题。

猜你喜欢

转载自blog.csdn.net/beguile/article/details/81452165
今日推荐