今天在一个普通类中注入service时出现了一个问题,我用@Autowired注入的service为null。最终我是通过以下方案解决的。
1.在类上标注该类为组件也就是@Component
2.静态初始化当前类
3.在初始化service的方法上加上注解@PostConstruct,这样方法就会在Bean初始化之后被Spring容器执行
4.调用时通过类来调用
今天在一个普通类中注入service时出现了一个问题,我用@Autowired注入的service为null。最终我是通过以下方案解决的。
1.在类上标注该类为组件也就是@Component
2.静态初始化当前类
3.在初始化service的方法上加上注解@PostConstruct,这样方法就会在Bean初始化之后被Spring容器执行
4.调用时通过类来调用
下一篇:layer.open传递json报错java.lang.IllegalArgumentException: Invalid character found in the request target
今天使用activiti的执行流程,使用dubbo想要去调用servic
昨日的问题的一个汇总
题说明最近看到Spring事务,在学习过程中遇到一个很苦恼问题 &
举报文章
请选择举报类型
补充说明
0/200
上传截图
格式支持JPEG/PNG/JPG,图片不超过1.9M