工具类的某个方法想要获取bean的实例,但是工具类的方法是static的,不能使用@Autowired 注入,方法解决
IOrderService epayOrderService = SpringContextHolder.getBean("orderService");
在xml注入SpringContextHolder
<!--使用xml 注入SpringContextHolder--> <bean id="springContextHolder" class="com.jamelLi.distributed.session.util.SpringContextHolder" />
一般来说,项目的util包,是不会被spring扫描到的。如果SpringContextHolder注入失败,说明没有被spring 扫描,需要增加下面的配置
<!-- 使用Annotation自动注册Bean --> <context:component-scan base-package="com.jamelLi.distributed.session.util"></context:component-scan>

浙公网安备 33010602011771号