记一次springboot 管理bean的错误

Q:

  在其他类中通过注解的方式注入service,测试的时候发现注入的为null

 public class test{

        @Autowired
       private utilService service; //为null


       private void util(){

          service.get();

          }

 }

  


A:在其他类中使用了new test(),导致该test类由自己管理,不受springboot管理, 所以该类中的service未被注入

 

猜你喜欢

转载自blog.csdn.net/lemon_linaa/article/details/79694307
今日推荐