Spring配置xml和属性脱离战争
我的目标是使SpringApplicationContext.xml和所有特定于环境的属性文件脱离war文件,从而使war文件独立于环境 1。外部化属性文件:我想我需要这样做Spring配置xml和属性脱离战争,xml,spring,spring-mvc,spring-boot,Xml,Spring,Spring Mvc,Spring Boot,我的目标是使SpringApplicationContext.xml和所有特定于环境的属性文件脱离war文件,从而使war文件独立于环境 1。外部化属性文件:我想我需要这样做 <property name="searchSystemEnvironment" value="true" /> <property name="locations"> <list> <value>file:///${MY_ENV_VAR_PATH}/
<property name="searchSystemEnvironment" value="true" />
<property name="locations">
<list>
<value>file:///${MY_ENV_VAR_PATH}/my.app.config.properties</value>
</list>
</property>
文件://${MY\u ENV\u VAR\u PATH}/MY.app.config.properties
这里也讨论过,
2。外部化SpringApplicationContext.xml:我可以使用外部化配置的SpringBoots功能
Q1:作为SpringBoot的新手,我不确定是否可以安全地删除/取消选择SpringBoot附带的所有不必要的功能,并将它们应用到我的项目中?我知道SpringBoot适用于从零开始的项目,就我而言,我正在从事一个成熟的项目
问题2:外部化配置是一种反模式吗?我使用上述方法的方向是否正确?由于我没有使用Spring boot,我只能回答您的第二个问题。 外部化配置绝对不是一种反模式。它增加了灵活性,并简化了(重新)在客户站点中的部署。事实上,我谈论的是外部化属性,而不是上下文配置。下面是我以前在tomcat中使用过的外部化属性的一个示例:
<bean name="appProperties" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<property name="locations">
<list>
<value>classpath:config-default/app.properties</value>
<value>file:${CATALINA_BASE}/conf/app-properties</value>
</list>
</property>
<property name="ignoreResourceNotFound" value="true" />
</bean>
classpath:config default/app.properties
文件:${CATALINA_BASE}/conf/app properties
第一个条目是内部条目,用于设置默认属性。第二个条目是指可选的外部化文件,客户可以编辑该文件以覆盖默认属性。您还可以传递第一个文件的子集,其中包含您认为安全的属性供客户修改。然后在每次更新中,目标环境中的设置都会被保留。
对我来说很有用