这是我的applicationContext.xml代码
<bean class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close" id="dataSource">
<property name="driverClassName" value="${database.driverClassName}" />
<property name="url" value="${database.url}" />
<property name="username" value="${database.username}" />
<property name="password" value="${database.password}" />
<property name="testOnBorrow" value="true" />
<property name="testOnReturn" value="true" />
<property name="testWhileIdle" value="true" />
<property name="timeBetweenEvictionRunsMillis" value="1800000" />
<property name="numTestsPerEvictionRun" value="3" />
<property name="minEvictableIdleTimeMillis" value="1800000" />
</bean>
我的属性在database.properties文件中定义命名
我需要什么样的变化在父pom.xml中做出的环境变量转换为目标运行时
能否请您帮助或者给我一个合适的建议或链接,可以让我的数据库属性的名称在运行时。对于如database.driverName
应更新为jdbcDriver
@Component
public class PropertyReloader {
@Autowired
private StandardEnvironment env;
@Scheduled(fixedRate=5000)
public void reloadProperties() throws IOException {
MutablePropertySources ps = env.getPropertySources();
Properties pr = new Properties();
InputStream inputStream = getClass().getResourceAsStream("/ApplicationContext.xml");
pr.load(inputStream);
inputStream.close();
pr.replace("class path resource [ApplicationContext.xml]", new PropertiesPropertySource("class path resource [ApplicationContext.xml]", pr));
}
}
这将在每五秒钟更新。
由于我的项目有各自的.properties
文件,我父母的pom.xml是只服用属性文件。这是无法获取其他属性文件。究其原因我的变量并没有在运行时获得更新。我保持着common.properties
文件,并加入pom.xml
路径
现在我得到了想要的结果