我有一个带有球衣的网络项目,试图使用可重复使用的罐子。这是我的球衣项目例外:
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [java.util.Properties] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true), @org.springframework.beans.factory.annotation.Qualifier(value=endpoints)}
集成jar的appContext:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util.xsd">
<util:properties id="endpoints" location="classpath:endpoints-${environment}.properties"/>
</beans>
我的java类应该接收该属性:
@Component
public class IntegrationService {
@Autowired
@Qualifier("endpoints")
private Properties endpoints;
public String get(String key) {
return endpoints.getProperty(key);
}
}
我做错了吗?
编辑如果我删除Qualifier
并确保属性名称与属性ID相同,那么我们可以使用例外情况。但问题是......我试着拿到我的钥匙而且我得到了空。
解决方案:从我的jar重命名applicationContext,然后:
<import resource="integration-applicationContext.xml"/>
答案 0 :(得分:0)
您必须在主应用程序上下文中导入集成jar的appContext。