创建名称为bean的bean时出错:org.springframework.beans.factory.NoSuchBeanDefinitionException

时间:2016-11-21 10:13:32

标签: java spring

我在Spring Framework的世界中相当新,并尝试通过Spring初始化一个对象'abcListener',它包含一个实例变量'algoMediator',我得到了以下异常。

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 Spring XML http://www.springframework.org/schema/beans/spring-beans.xsd”        默认自动装配= “绰号” &GT;

<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>

2 个答案:

答案 0 :(得分:0)

请检查AlgoMediator类中是否存在init()方法,否则删除init-method =“init”声明

答案 1 :(得分:0)

如果您创建任何新注入,请转到integration.xml并添加bean,它将解决问题。

示例

integration.xml

<bean id="exampleInjection" class="yourPackageName.className"> </bean>

中添加此内容
{{1}}