前几天我在我的代码库中发现了以下非正统的配置,这让我感到奇怪。当我将接口名称也用作 bean 的名称时,预期的 Spring Context 行为是什么?如果我在控制器中使用 @Autowireing 会有所不同吗?以下代码段说明了此设置:
interface MyAppService {...}
class InfrastructureService implements MyAppService {...}
class AdministrationService implements MyAppService {...}
class InfrastructureController {
// some code
public void setMyAppService(MyAppService svc){...}
}
<bean id="myAppService" class="InfrastructureService"/>
<bean id="administrationService" class="AdministrationService"/>
<bean id="infrastructureController" class="InfrastructureController">
<property name="myAppService" ref="myAppService"/>
</bean>
或者,如果仅将控制器定义为:
class InfrastructureController {
@Autowired
public void setMyAppService(MyAppService svc){...}
}