У меня есть проект Spring 3.0, который я пытаюсь подключить, который имеет зависимость от проекта библиотеки (также Spring 3.0), который имеет несколько классов, у которых есть свойства, вводимые через org.springframework.beans.factory .annotation.Value.Spring autowiring
Мне не нужны классы с загруженными свойствами, которые необходимо загрузить, и не вводимые свойства. Мне нужен только один конкретный класс, который должен быть автообновлен из проекта библиотеки.
я получаю следующее исключение:
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 как предложил один из ответов, это уже существует в моем проекте. Кроме того, я удалил все компоненты-scan и annotation-config из моих конфигурационных файлов 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
Может быть, лучше указать бит, который вам нужен, а не сканировать –
Ничего не похоже на вашу конфигурацию, но, возможно, ваш неудачный класс 'com.example.library.controller.App' предполагает, что Класс приложения аннотируется с помощью '@ Controller', а не' @ Service', поэтому вам может потребоваться изменить выражение в '