<?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:c="http://www.springframework.org/schema/c"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/jdbc
http://www.springframework.org/schema/jdbc/spring-jdbc.xsd
http://www.springframework.org/schema/jee
http://www.springframework.org/schema/jee/spring-jee.xsd">

<beans profile="dev">
<jdbc:embedded-database id="dataSource">
<jdbc:script location="classpath:xxx.sql"/>
<jdbc:script location="classpath:yyy.sql"/>
</jdbc:embedded-database>
</beans>
<beans profile="prod">
<jee:jndi-lookup jndi-name="jdbc/myDatabase" resource-ref="true" proxy-interface="javax.sql.DataSource"/>
</beans>
</beans>

 在web.xml中添加一个context-param来切换当前环境:

  1. <context-param>
  2. <param-name>spring.profiles.active</param-name>
  3. <param-value>develop</param-value>
  4. </context-param>

如果是测试类可以使用注解来切换:

  1. @ActiveProfiles("test")

spring3.1 profile 配置不同的环境的更多相关文章

  1. 160922、配置:spring通过profile或@profile配置不同的环境(测试、开发、生产)

    一.配置环境 applicationContext.xml中添加下边的内容(develop:开发环境,production:生产环境,test:测试环境) 注意:profile的定义一定要在文档的最下 ...

  2. spring boot: 一般注入说明(四) Profile配置,Environment环境配置 @Profile注解

    1.通过设定Environment的ActiveProfile来设置当前context所需要的环境配置,在开发中使用@Profile注解类或方法,达到不同情况下选择实例化不同的Bean. 2.使用jv ...

  3. maven不同环境的profile配置

    1.开发的时候经常需要加载不同的环境,比如本地开发环境dev,生产环境product.如果需要手动去修改的话就太麻烦了,自己实现了maven资源替换,然后多环境下的配置文件管理的demo,在此贴出来. ...

  4. SpringBoot系列四:SpringBoot开发(改变环境属性、读取资源文件、Bean 配置、模版渲染、profile 配置)

    声明:本文来源于MLDN培训视频的课堂笔记,写在这里只是为了方便查阅. 1.概念 SpringBoot 开发深入 2.具体内容 在之前已经基本上了解了整个 SpringBoot 运行机制,但是也需要清 ...

  5. SpringBoot开发(改变环境属性、读取资源文件、Bean 配置、模版渲染、profile 配置)

    1.概念 SpringBoot 开发深入 2.具体内容 在之前已经基本上了解了整个 SpringBoot 运行机制,但是也需要清楚的认识到以下的问题,在实际的项目开发之中,尤其是 Java 的 MVC ...

  6. 在/etc/profile下配置java的环境变量

    在/etc/profile下配置java的环境变量 原创 Java 作者:xiaoyan5686670 时间:2016-01-18 14:30:28  6152  0 以root用户编辑:#vi /e ...

  7. 在Linux虚拟机下配置jdk的环境变量

    1.到Oracle公司的官网里下载好jdk,网址 http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133 ...

  8. Linux下配置java的环境变量,So Easy!!

    首先,在cd /usr ,mkdir java. 将java安装包放到/usr/java,并解压. 验证java. $ java -version 如果提示有如下安装包包含它,但是没有安装.是环境变量 ...

  9. Ubuntu Linux下如何配置Android开发环境

    下载和安装Win7系统Android开发环境中讲了怎样在Win7系统中安装Android开发环境,那么怎样在Linux系统中配置Android开发环境呢?本篇文章就将演示如何使用Eclipse.And ...

随机推荐

  1. 基于zookeeper(集群)+LevelDB的ActiveMq高可用集群安装、配置、测试

    一. zookeeper安装(集群):http://www.cnblogs.com/wangfajun/p/8692117.html  √ 二. ActiveMq配置: 1. ActiveMq集群部署 ...

  2. Sql Server 游标例子笔记

    create PROCEDURE total_mySaleDuty as BEGIN DECLARE @a int,@error int DECLARE @b int,@errorb int DECL ...

  3. Oracle优化学习

    SQL执行效率对系统使用有很大影响,本文总结平时排查问题中遇到的一些Oracle优化问题的解决方案,或者日常学习所得. 1. Oracle sql执行顺序 sql语法的分析是从右到左. 1.1 SQL ...

  4. redis互斥锁简易设计原理【原】

    redis互斥锁设计 方式一: 使用 set(arg1,arg2,arg3,arg4,arg5) 绿线部分代码 //如果不存在就设置,且设置成功60秒后key自动失效,成功会返回字符串"OK ...

  5. JAVA中局部变量 和 成员变量有哪些区别

    JAVA中局部变量 和 成员变量有哪些区别 1.定义的位置不一样<重点>***局部变量:在方法的内部成员变量:在方法的外部,直接写在类当中 2.作用范围不一样<重点>***局部 ...

  6. Spark SQL基本概念与基本用法

    1. Spark SQL概述 1.1 什么是Spark SQL Spark SQL是Spark用来处理结构化数据的一个模块,它提供了两个编程抽象分别叫做DataFrame和DataSet,它们用于作为 ...

  7. iOS下如何阻止橡皮筋效果

    $(document).ready(function(){ var stopScrolling = function(event) { event.preventDefault(); } docume ...

  8. Image转Base64

    今天和一个朋友联调图片转Base64时发现一个问题 public static string ImageToBase64(Image img) { BinaryFormatter binFormatt ...

  9. udp_connect函数

    #include <netdb.h> #include <stdlib.h> #include <unistd.h> #include <string.h&g ...

  10. Linux之文件恢复[extundelete,针对rm]

    [恢复过程] 1.下载+安装extundelete cd /tmp wget wget http://jaist.dl.sourceforge.net/project/extundelete/extu ...