2017-05-25 109 views
0

我正尝试形式XML迁移到注释此代码:从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> 

我不知道如何迁移的地址的列表,我要创建的阵列资源(资源[]),但我如何迁移每个值?

@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
PropertiesFactoryBean fieldNamesProperties = new PropertiesFactoryBean(); 
fieldNamesProperties.setLocation(new ClassPathResource("/spring/file1.properties"));