在项目中,写工具类的时候用到了Servcie。但是由于工具类使用的是静态方法。Autowired注入的Service是非静态的所以不能够使用。
所以需要进行Spring的静态注入
private static Service service; @Autowired//必须放在setter函数前 public void setService(Service service)//这里的setService不能加static
{ ClassName.service =servcie;//ClassName为工具类的名字 }
同时工具类前要加@Component