2015-10-18 3 views
0

Недавно я решил сыграть с весной. Я сделал несколько уроков, и все кажется прекрасным до тех пор, пока я не пытаюсь использовать несколько файлов свойств. Как говорит интернет, достаточно сделать что-то вродепостоянная ошибка с именем бобов

<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> 
     <property name="ignoreUnresolvablePlaceholders" value="true"/> 
     <property name="ignoreResourceNotFound" value="true"/> 
     <property name="location"> 
      <list> 
       <value>classpath:readData.properties</value> 
       <value>classpath:sendMail.properties</value> 
      </list> 
     </property> 
</bean> 

Ну, к сожалению, это не работает. Неожиданно эта версия работает (для одной папки свойств):

<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> 
     <property name="location"> 
       <value>classpath:readData.properties</value> 
     </property> 
</bean> 

Консоль говорит следующим образом:

Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.beans.factory.config.PropertyPlaceholderConfigurer#0' defined in class path resource [Beans.xml]: Initialization of bean failed; nested exception is org.springframework.beans.TypeMismatchException: Failed to convert property value of type 'java.util.ArrayList' to required type 'org.springframework.core.io.Resource' for property 'location'; nested exception is java.lang.IllegalArgumentException: Cannot convert value of type [java.util.ArrayList] to required type [org.springframework.core.io.Resource] for property 'location': PropertyEditor [org.springframework.core.io.ResourceEditor] returned inappropriate value of type [java.util.ArrayList] 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:529) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458) 
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295) 
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223) 
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292) 
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:198) 
    at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:657) 
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:461) 
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139) 
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83) 
    at corrected_reminder.Reminder.main(Reminder.java:25) 
Caused by: org.springframework.beans.TypeMismatchException: Failed to convert property value of type 'java.util.ArrayList' to required type 'org.springframework.core.io.Resource' for property 'location'; nested exception is java.lang.IllegalArgumentException: Cannot convert value of type [java.util.ArrayList] to required type [org.springframework.core.io.Resource] for property 'location': PropertyEditor [org.springframework.core.io.ResourceEditor] returned inappropriate value of type [java.util.ArrayList] 
    at org.springframework.beans.BeanWrapperImpl.convertIfNecessary(BeanWrapperImpl.java:468) 
    at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:494) 
    at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:488) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.convertForProperty(AbstractAutowireCapableBeanFactory.java:1433) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1392) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1128) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519) 
    ... 10 more 
Caused by: java.lang.IllegalArgumentException: Cannot convert value of type [java.util.ArrayList] to required type [org.springframework.core.io.Resource] for property 'location': PropertyEditor [org.springframework.core.io.ResourceEditor] returned inappropriate value of type [java.util.ArrayList] 
    at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:260) 
    at org.springframework.beans.BeanWrapperImpl.convertIfNecessary(BeanWrapperImpl.java:448) 
    ... 16 more 

Может кто-нибудь мне помочь?

Редактировать

@Denis Макарский Я пробовал много раз, но не удовлетворительные результаты. Теперь у меня есть

Exception in thread "main" org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Cannot locate BeanDefinitionDecorator for element [property-placeholder] 
Offending resource: class path resource [Beans.xml] 

ответ

0

Вы можете использовать тег property-placeholder context, чтобы указать несколько файлов свойств.

Пример:

<context:property-placeholder location="readData.properties, 
              sendMail.properties"/> 

Не забудьте добавить Context схемы тэгу фасоли, как это:

<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-3.1.xsd 
         http://www.springframework.org/schema/context 
         http://www.springframework.org/schema/context/spring-context-3.1.xsd> 
2

Вы используете файл несколько свойств, используйте "место" вместо «местоположения». Для отдельных свойств вы можете использовать «местоположение».

Проверьте апи документ: https://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/core/io/support/PropertiesLoaderSupport.html#setLocations-org.springframework.core.io.Resource...-

Смежные вопросы