很简单,声明一个PropertiesFactoryBean
.
@Bean(name = "mapper")
public PropertiesFactoryBean mapper() {
PropertiesFactoryBean bean = new PropertiesFactoryBean();
bean.setLocation(new ClassPathResource("com/foo/jdbc-production.properties"));
return bean;
}
在此处的文档中,您会注意到,在他们制作之前<util:properties>
,他们曾经使用 aPropertiesFactoryBean
原样
<!-- creates a java.util.Properties instance with values loaded from the supplied location -->
<bean id="jdbcConfiguration" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<property name="location" value="classpath:com/foo/jdbc-production.properties"/>
</bean>
如上所示,将其转换为 Java 配置非常简单。