spring.profiles.active配置多种spring启动环境
来源:互联网 发布:mac 按键精灵 编辑:程序博客网 时间:2024/05/17 13:10
我们在开发的时候,经常会需要多种环境,比如开发环境,测试环境,生产环境的数据库地址是不一样的。spring mvc环境下如何配置呢?
在web.xml里面有个属性,可以配置。
比如我们配置测试环境。
<context-param> <param-name>spring.profiles.active</param-name> <param-value>test</param-value> </context-param>
在spring xml配置文件这么配置<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans"xmlns:jee="http://www.springframework.org/schema/jee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:jpa="http://www.springframework.org/schema/data/jpa" xmlns:tx="http://www.springframework.org/schema/tx"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsdhttp://www.springframework.org/schema/data/jpahttp://www.springframework.org/schema/data/jpa/spring-jpa-1.1.xsdhttp://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.1.xsd"><bean id="propertyConfigurer"class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"><property name="location" value="classpath:database.properties" /></bean> <beans profile="prod"><jee:jndi-lookup id="dataSource" jndi-name="${jpreTest.datasource}"resource-ref="true" /><jee:jndi-lookup id="dataSource2" jndi-name="${jpreTest.datasource2}"resource-ref="true" /></beans><beans profile="test"> <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"><property name="driverClass" value="${jpreTest.connection.driver_class}" /><property name="jdbcUrl" value="${jpreTest.connection.url}" /><property name="user" value="${jpreTest.connection.username}" /><property name="password" value="${jpreTest.connection.password}" /><!-- 初始线程数 --> <property name="initialPoolSize" value="5" /> <!-- 最小线程数 --> <property name="minPoolSize" value="${jpreTest.minPoolSize}" /> <!-- 最大线程数 --> <property name="maxPoolSize" value="${jpreTest.maxPoolSize}" /> <!-- 空闲时间,单位秒 --> <property name="maxIdleTime" value="1200" /> <!-- 获取连接失败后该数据源将申明已断开并永久关闭 --> <property name="breakAfterAcquireFailure" value="true" /> <!--每60秒检查所有连接池中的空闲连接。Default: 0 --> <property name="idleConnectionTestPeriod" value="60"/> <!--如果设为true那么在取得连接的同时将校验连接的有效性。Default: false --> <property name="testConnectionOnCheckin" value="true" /> <!-- 链接池耗尽时一次获取的连接数 --> <property name="acquireIncrement" value="5" /></bean> <bean id="dataSource2" class="com.mchange.v2.c3p0.ComboPooledDataSource"><property name="driverClass" value="${jpreTest.connection.driver_class}" /><property name="jdbcUrl" value="${jpreTest.connection.url2}" /><property name="user" value="${jpreTest.connection.username2}" /><property name="password" value="${jpreTest.connection.password2}" /><!-- 初始线程数 --> <property name="initialPoolSize" value="5" /> <!-- 最小线程数 --> <property name="minPoolSize" value="${jpreTest.minPoolSize}" /> <!-- 最大线程数 --> <property name="maxPoolSize" value="${jpreTest.maxPoolSize}" /> <!-- 空闲时间,单位秒 --> <property name="maxIdleTime" value="1200" /> <!-- 获取连接失败后该数据源将申明已断开并永久关闭 --> <property name="breakAfterAcquireFailure" value="true" /> <!--每60秒检查所有连接池中的空闲连接。Default: 0 --> <property name="idleConnectionTestPeriod" value="60"/> <!--如果设为true那么在取得连接的同时将校验连接的有效性。Default: false --> <property name="testConnectionOnCheckin" value="true" /> <!-- 链接池耗尽时一次获取的连接数 --> <property name="acquireIncrement" value="5" /></bean></beans></beans>
0 1
- spring.profiles.active 针对多种启动环境的spring配置
- spring.profiles.active配置多种spring启动环境
- spring.profiles.active 针对多种启动环境的spring配置
- spring.profiles.active 针对多种启动环境的spring配置
- spring.profiles.active
- Spring.profiles多环境配置
- spring.profiles.active=dev
- springboot 使用spring.profiles.active来分区配置
- Spring.profiles多环境配置原理
- Spring mvc 多种环境配置
- java编程中spring boot 使用spring.profiles.active来分区配置
- Spring 启动时报No active profile set, falling back to default profiles default
- spring boot启动报错:No active profile set, falling back to default profiles: default
- 使用 spring.profiles.active 及 @profile 注解 动态化配置内部及外部配置
- spring boot中spring.profiles.active的用法
- spring profiles
- spring profiles实现不同的环境配置的一键切换
- Spring boot @Test的时候需要设置 环境变量:spring.profiles.active = dev
- 字节输入输出流
- 重新认识了下Entity Framework
- 为apache配置多个虚拟机
- lua中的table使用陷阱
- GMTSAR(GMT4SAR、GMT5SAR)
- spring.profiles.active配置多种spring启动环境
- 如何在MAVEN中配置Spring的依赖包
- 算法训练 删除数组零元素
- ViewPager + Fragment 多个fragment后几页显示不正常问题
- 统计学5
- openMP之一简单的并行循环
- 测试开发之路--一个小小工程师的回首
- 笔记
- POJ 1004 - Financial Management