自Spring 3.1.3起的NoSuchBeanDefinitionException

时间:2013-11-27 15:42:18

标签: exception javabeans spring-3 autowired

我今天在我的应用程序中使用了Spring版本。我从Spring 3.1.1开始,当我转到Spring 3.1.3时,我的应用程序在启动时开始抛出NoSuchBeanDefinitionException。

  

org.springframework.beans.factory.NoSuchBeanDefinitionException:没有   匹配类型的bean   找到[nl.my.product.properties.Properties]   依赖:预计至少有1个bean有资格成为autowire   这种依赖的候选人。依赖注释:{}

我在应用程序上下文中配置了Properties bean,如下所示:

<!-- Gather properties from environment.properties in a map -->
<bean id="systemProperties" class="nl.my.product.properties.Properties">
    <property name="propertyMap">
        <map>
            <entry key="email.from.address" value="${email.from.address}"/>
            <entry key="site.host" value="${site.host}"/>
            <entry key="site.protocol" value="${site.protocol}"/>
            ...
        </map>
    </property>
</bean>

我将bean自动装入我的许多控制器和服务中,如下所示:

@Autowired
public ArticleController(ArticleService articleService, PageBlockService pageBlockService, Properties systemProperties) {
    this.articleService = articleService;
    this.pageBlockService = pageBlockService;
    this.properties = systemProperties;
}

有关为什么Spring自Spring 3.1.3以来无法找到我的bean的任何线索?我尝试将Properties bean移动到包中,但是也没有扫描组件,但这并没有解决问题。

当我使用@Component注释Properties bean时,Spring会选择它,但是属性贴图是空的。

1 个答案:

答案 0 :(得分:0)

当我从bean定义

中删除id="systemProperties"时,它开始工作