zoukankan      html  css  js  c++  java
  • spring3.1 profile 配置不同的环境

    <?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来切换当前环境:

    Java代码  收藏代码
    1. <context-param>  
    2.     <param-name>spring.profiles.active</param-name>  
    3.     <param-value>develop</param-value>  
    4. </context-param>  

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

    Java代码  收藏代码
    1. @ActiveProfiles("test")  
  • 相关阅读:
    MySQL动态添删改列字段
    关于javascript在子页面中函数无法调试问题的解决
    <T> T[] toArray(T[] a);
    MERGE INTO
    eclipse不能新建server
    关于tomcat7下websocket不能使用
    myeclipse启动tomcat报错cannot find a free socket for debugger
    checkbox提交多组数据到action
    Struts2 Action中的方法命名不要以get开头
    浅谈C#中的接口和抽象类
  • 原文地址:https://www.cnblogs.com/sddychj/p/6668246.html
Copyright © 2011-2022 走看看