我有一颗豆子:
<bean id="BasketLogic" class="efco.logic.EfcoBasketLogic" autowire="byType">
<property name="documentLogic" ref="DocumentLogic" />
<property name="stateAccess" ref="StateAccess" />
<property name="contextAccess" ref="ContextAccess" />
</bean>
<bean id="EfcoErpService" autowire="byType" class="efco.erp.service.EfcoErpServiceImpl">
<constructor-arg ref="ErpConnector"/>
</bean>
文档逻辑, 状态访问 and 上下文访问字段是否在篮子逻辑实现
而我没有<context:component-scan />
EfcoBasketLogic.java:
public class EfcoBasketLogic extends BasketLogicImpl {
@Inject
private EfcoErpService erpService;
...
...
...
}
erp服务是null,除非我提供一个设置器。但为什么?我认为发生自动装配的地方不需要设置器?难道是 BasketLogicImpl 造成的吗?
您需要使用setter,因为除非通过任一方式告诉spring,否则不会检测到注释<context:component-scan />
or <context:annotation-config />
。检测到 Setter 因为您指定了autowire="byType"
.
您可能会发现这个问题和答案也很有帮助:何时在 Spring 中使用自动装配 https://stackoverflow.com/questions/12920606/when-to-use-autowiring-in-spring/12920796#12920796
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)