我面临的问题是,如果我从配置中删除组件扫描标记,则注释 @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 上并具有设置器。
我做错了什么?