1
我在Spring框架的世界裏很新,嘗試通過Spring初始化一個對象'abcListener',它包含一個實例變量'algoMediator'和I我得到了異常。使用名稱創建bean時出錯:org.springframework.beans.factory.NoSuchBeanDefinitionException
Error creating bean with name 'abcListener' defined in class path resource [eventcreation/integration.xml]: Cannot resolve reference to bean 'liabilityService' while setting bean property 'algoMediator'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'liabilityService' is defined.
在Spring XML中,我定義瞭如下的bean。
<bean id="abcListener" class="services.integration.AbcListener">
<property name="algoMediator" ref="liabilityService"/>
</bean>
的Java類是
public class AbcListener
{
private AlgoMediator algoMediator;
public void setAlgoMediator(AlgoMediator algoMediator) {
this.algoMediator = algoMediator;
}
}
我曾在項目在太多的地方檢查intsance variabale bean是在相同的方式爲「liabilityService」定義在不同的文件中定義,但它不接受我的定義。
的liabilityService彈簧XML是 http://www.springframework.org/schema/beans/spring-beans.xsd」 默認自動裝配= 「綽號」>
<alias name="liabilityService" alias="algoMediator"/>
<bean id="liabilityService" class="services.liability.impl.AlgoMediator" init-method="init" >
<property name="eventLiabilityMonitoringInterval" value="${liability.eventLiabilityMonitoringInterval}"/>
<property name="fastTrackedSuspensions" value="${ms.fastTrackedSuspensions:false}"/>
<property name="blurInterval" value="${liability.ms.blurInterval}"/>
<property name="publishActualOffTime" value="${ms.publishActualOffTime}"/>
<property name="transactionManager" ref="transactionManager"/>
<property name="liabilityDatasource" ref="liabilityDatasource"/>
<property name="liabilityScaleFactor" value="${liability.scaleFactor:0}"/>
<property name="sportsWithoutMarketAlerts" value="${alerts.sportsWithoutMarketAlerts}"/>
</bean>
如何在您的'liabilityService'定義在這個不同的文件中,發佈所有Spring xml設置 – pleft
liabilityService定義如下 –
你應該在'AbcListener'中爲bean'algoMediator'設置setter和getters。 – Raghuveer