Juan Reina Pascual
Juan Reina Pascual

Reputation: 4648

migrating from XML to annotations (spring)

I´m trying to migrate form XML to annotations this code:

<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>

I don´t know how to migrate the locations lists, I have to create a array of Resources (Resource[]), but how can I migrate each value?

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

   fieldNamesProperties.setLocations(locations);
   return fieldNamesProperties;
}

Upvotes: 0

Views: 74

Answers (1)

StanislavL
StanislavL

Reputation: 57421

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

Upvotes: 1

Related Questions