从XML迁移到注释(spring)

时间:2017-05-25 15:33:09

标签: java spring annotations

我正在尝试将表单XML迁移到注释代码:

<bean       
class="org.springframework.beans.factory.config.PropertiesFactoryBean">
  <property name="ignoreResourceNotFound" value="true" />
  <property name="locations">
     <list>
       <value>classpath:spring/file1.properties</value>
       <value>file:${file.prop}</value>
     </list>
   </property>
</bean>

我不知道如何迁移位置列表,我必须创建一个Resources(Resource [])数组,但是如何迁移每个值?

@Bean
public PropertiesFactoryBean fieldNamesProperties() {
   PropertiesFactoryBean fieldNamesProperties = new PropertiesFactoryBean();
   fieldNamesProperties.setIgnoreResourceNotFound(true);
   Resource[] locations = new Resource[2];
   // TODO add resources

   fieldNamesProperties.setLocations(locations);
   return fieldNamesProperties;
}

1 个答案:

答案 0 :(得分:1)

PropertiesFactoryBean fieldNamesProperties = new PropertiesFactoryBean();
fieldNamesProperties.setLocation(new ClassPathResource("/spring/file1.properties"));