我在代碼庫中發現了下面的非正統配置,這讓我很想知道。當我使用接口名稱作爲bean的名稱時,預期的Spring Context行爲是什麼?如果我在控制器中使用@Autowiring,它會有所作爲嗎?下面的代碼片段說明了這個設置:如果只控制器被定義爲將接口名稱也作爲bean名稱時的彈簧行爲?
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){...}
}
沒有shokes我你的代碼。 – Mik378