Gar*_*lon 8 spring explicit autowired
我面临的问题是,如果从配置中删除组件扫描标记,注释@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...
Run Code Online (Sandbox Code Playgroud)
efco.auth包中只有一个类,这个类与以下类EfcoBasketLogic无关.
和一个使用@Autowired的类:
package efco.logic;
public class EfcoBasketLogic extends BasketLogicImpl {
@Autowired
private EfcoErpService erpService;
Run Code Online (Sandbox Code Playgroud)
这个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>
Run Code Online (Sandbox Code Playgroud)
如您所见,未定义erpService.其他三个属性在BasketLogicImpl上并且有setter.
我做错了什么?
art*_*tol 15
As Tomasz says, you need <context:annotation-config/> for @Autowired to work. When you had <context:component-scan/>, it implicitly included annotation-config for you.
| 归档时间: |
|
| 查看次数: |
7942 次 |
| 最近记录: |