我正在尝试在Spring中实现https://github.com/jamesmorgan/ReloadablePropertiesAnnotation并且无法弄清楚问题。
我已尝试过其他解决方案,说明正确添加组件扫描包但看起来,这不是解决此问题的方法。
通过xml查找依赖:它尝试创建bean ReloadablePropertyPostProcessor并使用依赖于ReadablePropertySourcesPlaceholderConfigurer的构造函数注入值
这是stacktrace:
**org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'reloadablePropertyPostProcessor' defined in file** [/Users/xxxxx/Documents/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/spring3-mvc-maven-xml-hello-world/WEB-INF/classes/com/demo/design/properties/internal/ReloadablePropertyPostProcessor.class]: **Unsatisfied dependency expressed through constructor argument with index 0 of type** [com.demo.design.properties.internal.ReadablePropertySourcesPlaceholderConfigurer]: : No qualifying bean of type [com.demo.design.properties.internal.ReadablePropertySourcesPlaceholderConfigurer] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.demo.design.properties.internal.ReadablePropertySourcesPlaceholderConfigurer] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:752)
at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:193)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1077)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:981)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:487)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:293)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:290)
at
...
...
...
org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
**Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.demo.design.properties.internal.ReadablePropertySourcesPlaceholderConfigurer] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}**
at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:997)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:867)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:779)
at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:817)
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:745)
... 37 more
这是我的spring-reloadableProperties.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
">
<import resource="classpath:/spring/spring-defaultConfiguration.xml" />
<bean
class="com.demo.design.properties.internal.ReloadablePropertyPostProcessor">
<constructor-arg ref="propertyConfigurator" />
<constructor-arg ref="eventNotifier" />
<constructor-arg ref="conversionService" />
</bean>
<bean id="propertyConfigurator"
class="com.demo.design.properties.internal.ReadablePropertySourcesPlaceholderConfigurer">
<property name="ignoreUnresolvablePlaceholders" value="false" />
<property name="ignoreResourceNotFound" value="true" />
<constructor-arg ref="eventNotifier" />
<constructor-arg ref="propertyResolver" />
<property name="locations">
<list>
<value>classpath*:META-INF/*.properties</value>
<value>classpath:config.properties</value>
<!-- <value>file:${CONFIG_DIR}/global.properties</value> -->
</list>
</property>
</bean>
</beans>