我面临的问题是,如果我从配置中删除组件扫描标记,则注释 @Autowired 不再起作用(在使用此注释的所有 Java 类中)
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<context:component-scan base-package="efco.auth" />
here are some beans...
efco.auth 包中只有一个类,该类与下面的 EfcoBasketLogic 类没有关系。
和一个使用 @Autowired 的类:
package efco.logic;
public class EfcoBasketLogic extends BasketLogicImpl {
@Autowired
private EfcoErpService erpService;
这个 Bean 在另一个 spring 配置文件中定义:
<bean id="BasketLogic" class="efco.logic.EfcoBasketLogic">
<property name="documentLogic" ref="DocumentLogic" />
<property name="stateAccess" ref="StateAccess" />
<property name="contextAccess" ref="ContextAccess" />
</bean>
如您所见,erpService 未定义。其他三个属性位于 BasketLogicImpl 上并具有设置器。
我做错了什么?
正如托马斯所说,你需要<context:annotation-config/>
for @Autowired
上班。当你有<context:component-scan/>
,它隐含地包含了annotation-config
为你。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)