我有一个春天3.0项目,我试图连线,有一个库项目(也是春天3.0)的依赖项有几个类的属性被注入通过org.springframework.beans.factory .annotation.Value。春天自动装配
我不需要加载注入属性的类,也不需要注入属性。我只需要从图书馆项目中自动装配一个特定的类。
我不断收到以下异常:
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private java.lang.String com.example.library.controller.App.dir; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'app.achDir'
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:502)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:84)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:282)
... 38 more
Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'app.achDir'
at org.springframework.util.PropertyPlaceholderHelper.parseStringValue(PropertyPlaceholderHelper.java:173)
at org.springframework.util.PropertyPlaceholderHelper.replacePlaceholders(PropertyPlaceholderHelper.java:125)
at org.springframework.beans.factory.config.PropertyPlaceholderConfigurer$PlaceholderResolvingStringValueResolver.resolveStringValue(PropertyPlaceholderConfigurer.java:403)
at org.springframework.beans.factory.support.AbstractBeanFactory.resolveEmbeddedValue(AbstractBeanFactory.java:736)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:713)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:703)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:474)
... 40 more
这里是我的applicationContext.xml的片段。我尝试了以下几种版本,但排除/包含过滤器似乎不起作用。
<context:component-scan base-package="com.example.library" >
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Service"/>
</context:component-scan>
我正在使用一个PropertyPlaceholderConfigurer,如其中一个答案所示,这已经存在于我的项目中。另外,我从Spring配置文件中删除了所有的组件扫描和注解配置。
<!-- Define the other the old-fashioned way, with 'ignoreUnresolvablePlaceholders' set to TRUE -->
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>src/test/resources/my.properties</value>
<value>my.properties</value>
</list>
</property>
<property name="ignoreResourceNotFound" value="true"/>
</bean>
我要补充一点,出现这种错误运行扩展与以下注释超类单元测试时:
@TransactionConfiguration(defaultRollback = true,transactionManager="txManager")
@Transactional
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath*:applicationContext.xml")
public abstract class BaseTest {
如果你告诉我哪个图书馆可能可以帮忙。错误是非常奇怪的 – emd 2013-03-22 22:32:55
可能是更好的选项来声明你需要的bean而不是扫描 – 2013-03-22 23:02:19
你的配置似乎没有错,但也许你失败的类'com.example.library.controller.App'建议应用程序类用'@ Controller'注释,而不是'@Service',所以你可能需要在'中改变表达式。'无论如何,我会用一个属性源来解决这个问题。 “app.achDir”的“不关心”值,因为你不用它(和bean) –
2013-03-22 23:40:31