我已经读了几十篇关于Spring的文章,但找不到这个问题的优雅解决方案。弹簧属性配置
a)使用PropertyPlaceholderConfigurer加载属性文件。例如。
// Load properties file
@Bean(name = "appProperties")
public static PropertyPlaceholderConfigurer getApplicationProperties() {
PropertyPlaceholderConfigurer bean = new PropertyPlaceholderConfigurer();
bean.setLocation(new ClassPathResource("app.properties"));
return bean;
}
b)求使用PropertyPlaceHolderConfigurer(例如mysql.properties在与此相关的数据库类型 “app.properties” app.database = MySQL的
C),然后负载属性中配置的数据库类型)并使其在上下文豆类
可用
嗨@Romail
${property name}
,请看看这个:http://kruders.com/spring/spring-propertyplaceholderconfigurer-使用注释/ – Backtrack此链接不起作用。我想根据app.properties中定义的属性加载新的属性文件 –