我正在尝试将 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>
我不知道如何迁移位置列表,我必须创建一个资源数组 (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;
}
最佳答案
PropertiesFactoryBean fieldNamesProperties = new PropertiesFactoryBean();
fieldNamesProperties.setLocation(new ClassPathResource("/spring/file1.properties"));
关于java - 从 XML 迁移到注释 (spring),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44184351/