在Java类中取web.xml中配置的profile
肉类菜肴一般放在中间位置,便于大家夹取分配。 #生活常识# #日常生活小窍门# #餐桌小技巧# #餐桌上菜顺序#
一般情况下,通过web.xml,spring profile的配置,搭配具体的配置文件,就可以实现配置文件的快速切换了,
但,有时候自己编写代码读配置文件,这个时候最好也根据环境读具体的配置
public class PropertiesConstant {
private static String profile = "" ;
static {
WebApplicationContext webApplicationContext = ContextLoader.getCurrentWebApplicationContext();
ServletContext servletContext = webApplicationContext.getServletContext();
profile = servletContext.getInitParameter("spring.profiles.active");
if(profile != null){
profile += "/";
}
else{
profile = "";
}
}
private static Properties props = PropertiesUtil.readProperty("/conf/resource/" + profile + "resource.properties");
public static final String SSO_DOMAIN_BASE_USRL = props.getProperty("SSO_DOMAIN_BASE_USRL");
web.xml
<context-param>
<param-name>spring.profiles.default</param-name>
<param-value>development</param-value>
</context-param>
<context-param>
<param-name>spring.profiles.active</param-name>
<param-value>smart</param-value>
</context-param>
<context-param>
<param-name>spring.liveBeansView.mbeanDomain</param-name>
<param-value>development</param-value>
</context-param>
spring-profile配置
<description>spring profile配置</description>
<beans profile="development">
<context:property-placeholder
location="classpath:conf/resource/development/*.properties" />
</beans>
<beans profile="production">
<context:property-placeholder
location="classpath:conf/resource/production/*.properties" />
</beans>
<beans profile="release">
<context:property-placeholder
location="classpath:conf/resource/release/*.properties" />
</beans>
网址:在Java类中取web.xml中配置的profile https://www.yuejiaxmz.com/news/view/116806
相关内容
037基于java+springboot的课外学习生活活动平台系统Java 在生活中的 10 大应用
Java——String类
java中intx=1 y=2
JAVA题目
Java程序员不得不会的124道面试题(含答案)
JAVA计算机毕业设计基于Springboot的在线教育平台的设计与实现(附源码+springboot+开题+论文)
10年Java面试总结:Java程序员面试必备的面试技巧
java社区便民app(开题+源码)
【Java】基础类型之float(八)