Spring中激活profile的方法:设置spring.profiles.active和spring.profiles.default这两个属性
设置激活profile属性的地方(优先级由高到底)
0)Spring上下文
ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext(EnvironmentApp.class);
ConfigurableEnvironment env = ctx.getEnvironment();
或
ApplicationContext ctx = new AnnotationConfigApplicationContext(EnvironmentApp.class);
Environment _e =ctx.getEnvironment();
ConfigurableEnvironment env = ConfigurableEnvironment.class.cast(_e);
//通过setActiveProfiles来设置。
env.setActiveProfiles("wow","pes","ff"); 
//必须重建容器
ctx.refresh();
 
1)ServletConfig parameters(if applicable, e.g. in case of a DispatcherServlet context)
<init-param>
<param-name>spring.profiles.active</param-name>
<param-value>dev</param-value>
</init-param>
 
2)ServletContext parameters(web.xml context-param entries)
<context-param>
<param-name>spring.profiles.active</param-name>
<param-value>dev</param-value>
</context-param>
 
3)JNDI environment variables
 
4)JVM system properties
JVM system properties的设置方式
a) 设置JVM的启动参数 -D<name>=<value> ("-D" command-line arguments)
   i) 在tomcat内的catalina.bat(.sh中不用"set")中加 JAVA_OPTS="-Dspring.profiles.active=dev"
   ii) eclipse中设置run configuration:-Dspring.profiles.active=dev
b) JAVA标准API:
   System.setProperty("spring.profiles.active", "dev");//在启动容器之前,先指定环境中的profiles参数
   ApplicationContext ctx = new AnnotationConfigApplicationContext(EnvironmentApp.class);
   
5)OS environment variable
  增加环境变量,eg.spring.profiles.active=dev
  读取配置文件 <context:property-placeholder location="classpath:config_${spring.profiles.active}.properties" ignore-unresolvable="true"  />
 
 
JNDI environment variables ("java:comp/env/" entries)

在集成测试类上,使用@ActiveProfiles注解配置。

Spring激活profile的方式的更多相关文章

  1. 几种激活Profile的方式

    方法一: 选择spring.profiles.active spring.profiles.active=prodspring.profiles.active=dev 方法二: 选择spring.pr ...

  2. spring boot-6.profile 多环境支持

    在正式项目中一般都会区分多个环境,一般至少分为开发环境,测试生产环境,生产环境,实际可能会有更加精细的区分,针对不同的环境,项目的配置可能需要切换,spring boot 提供了很方便的环境切换方式. ...

  3. 【转】Spring Boot Profile使用

    http://blog.csdn.net/he90227/article/details/52981747 摘要: spring Boot使用@Profile注解可以实现不同环境下配置参数的切换,任何 ...

  4. 【Java Web开发学习】Spring环境profile

    [Java Web开发学习]Spring 环境profile 转载:http://www.cnblogs.com/yangchongxing/p/8890702.html 开发.测试.生产环境往往是不 ...

  5. 十、Spring的@Profile注解

    首先我们来看看spring官方文档对这个注解的解释: The @Profile annotation allows you to indicate that a component is eligib ...

  6. 【译】Spring 4 @Profile注解示例

    前言 译文链接:http://websystique.com/spring/spring-profile-example/ 本文将探索Spring中的@Profile注解,可以实现不同环境(开发.测试 ...

  7. Spring 梳理-profile与条件化定义bean

    定义profile <beans> //root <beans profile="dev"> <bean id=.../> </beans ...

  8. WebStorm 2016 最新版激活(activation code方式)

    WebStorm 2016 最新版激活(activation code方式) WebStorm activation code WebStorm 最新版本激活方式: 今天下载最新版本的WebStorm ...

  9. spring aop 使用注解方式总结

    spring aop的注解方式:和xml的配置方式略有区别,详细如下: 1.首先还是建立需要的切面类:切面类里面定义好切点配置,以及所有的需要实现的通知方法. /** * */ package com ...

随机推荐

  1. 462. Minimum Moves to Equal Array Elements II

    Given a non-empty integer array, find the minimum number of moves required to make all array element ...

  2. python 对象(object)

  3. 【风马一族_软件】微软卸载工具_msicuu2.exe

    msicuu2.exe是微软的Windows Installer清理工具,可以用来清理微软安装包软件产生的垃圾,当然也可以拿来作为修复相关软件的卸载准备使用 下载链接:http://files.cnb ...

  4. python 异常处理与流程控制

  5. @atcoder - AGC038F@ Two Permutations

    目录 @description@ @solution@ @accepted code@ @details@ @description@ 给定 N 与两个 0~N-1 的置换 P, Q. 现在你需要找到 ...

  6. 阿里云DataWorks正式推出Stream Studio:为用户提供大数据实时计算的数据中台

    5月15日 阿里云DataWorks正式推出Stream Studio,正式为用户提供大数据的实时计算能力,同时标志着DataWorks成为离线.实时双计算领域的数据中台. 据介绍,Stream St ...

  7. @hdu - 6594@ Double Tree

    目录 @description@ @solution@ @accepted code@ @details@ @description@ 给定两棵 N 个点的树,以及树上每条边的权值 w(u, v),每 ...

  8. @codeforces - 1096G@ Lucky Tickets

    目录 @description@ @solution@ @accepted code@ @details@ @description@ 已知一个数(允许前导零)有 n 位(n 为偶数),并知道组成这个 ...

  9. 【Bzoj1875】HH去散步

    [Bzoj1875]HH去散步 先说一下边点互化的思路(貌似这种题不多?),以后看见边数少的要死的记得想边点乎化,将无向边变成有向边在考虑边之间的可达性,如果边x的终点是边y的起点(前提不是同一条边) ...

  10. Object-c学习笔记十八-----NSPredicate

    Cocoa提供了一个类NSPredicate类,该类主要用于指定过滤器的条件,该对象可以准确的描述所需条件,对每个对象通过谓词进行筛选,判断是否与条件相匹配.谓词表示计算真值或假值的函数. NSPre ...