Spring ApplicationContext.xml不会在目标位置更新环境变量
这是我的ApplicationContext.xml代码Spring ApplicationContext.xml不会在目标位置更新环境变量,spring,hibernate,datasource,applicationcontext,Spring,Hibernate,Datasource,Applicationcontext,这是我的ApplicationContext.xml代码 <bean class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close" id="dataSource"> <property name="driverClassName" value="${database.driverClassName}" /> <propert
<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>
我的属性在名为数据库的文件中定义。属性
我需要在父pom.xml中进行哪些更改,以在目标运行时转换env变量
请您提供帮助或给我一个适当的建议或链接,以便在运行时获取数据库属性的名称。
例如
数据库.driverName
应更新为jdbcDriver
@组件
公共类PropertyReader{
@自动连线
私人标准环境;
@计划(固定利率=5000)
public void reloadProperties()引发IOException{
可变属性资源ps=env.getPropertySources();
Properties pr=新属性();
InputStream InputStream=getClass().getResourceAsStream(“/ApplicationContext.xml”);
pr.load(输入流);
inputStream.close();
pr.replace(“类路径资源[ApplicationContext.xml]”,新属性PropertySource(“类路径资源[ApplicationContext.xml]”,pr));
}
}
这将每五秒钟更新一次。因为我的项目必须使用相应的
.properties
文件,而我的父pom.xml只使用.properties文件。它无法获取另一个.properties文件。我的变量在运行时未得到更新的原因。我维护了一个common.properties
文件,并在pom.xml
现在我得到了所需的结果我的父pom.xml已经定义了env标记和其中指定的路径,但是在目标上实际名称没有被调用。