使用Maven管理spring环境的profile定义
来源:互联网 发布:debian ubuntu 对比 编辑:程序博客网 时间:2024/06/13 11:34
开发过程中需要针对开发环境,正式环境等进行不同的参数配置,比如开发环境使用H2数据库做简单测试,正是环境使用mysql数据库。如果手动管理这些配置信息会很麻烦,最重要的是可能会因为操作失误导致一些错误。因此需要对不同环境的配置信息进行集中管理。
spring 3.1版本提供了profile配置机制,同时maven对profile也有支持,我们将使用mavne + spring 的profile管理不同环境的配置数据。
3.将web.xml文件移动到 src/main/build目录下,在maven的pom文件中加入如下配置
spring 3.1版本提供了profile配置机制,同时maven对profile也有支持,我们将使用mavne + spring 的profile管理不同环境的配置数据。
1.在spring配置文件中配置加载不同配置文件
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd"> <!-- 本地测试环境 --> <beans profile="localtest"> <bean id="config" class="org.springframework.beans.factory.config.PropertiesFactoryBean" p:locations="classpath*:/config/*.localtest.properties" /> </beans> <!-- 正式环境 --> <beans profile="pro"> <bean id="config" class="org.springframework.beans.factory.config.PropertiesFactoryBean" p:locations="classpath*:/config/*.pro.properties" /> </beans></beans>
2.web.xml文件:
<?xml version="1.0" encoding="UTF-8"?><web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" metadata-complete="true" version="2.5"> <context-param> <param-name>spring.profiles.active</param-name> <param-value>${profiles.active}</param-value><!--环境配置信息 --> </context-param> <context-param> <param-name>contextConfigLocation</param-name> <param-value> classpath:config/application.xml </param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <welcome-file-list> <welcome-file>index.html</welcome-file> <welcome-file>index.jsp</welcome-file> </welcome-file-list></web-app>
3.将web.xml文件移动到 src/main/build目录下,在maven的pom文件中加入如下配置
<profiles> <!-- 本地测试环境 --> <profile> <id>localtest</id> <properties> <profiles.active>localtest</profiles.active> </properties> <activation> <!-- 默认启用的是本地测试环境 --> <activeByDefault>true</activeByDefault> </activation> </profile> <!-- 部署环境 --> <profile> <id>pro</id> <properties> <profiles.active>pro</profiles.active> </properties> </profile></profiles>....//其他配置信息<build> <plugins> <!-- 根据环境动态生成web.xml文件 --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-resources-plugin</artifactId> <version>2.5</version> <executions> <execution> <id>copy-resources</id> <phase>compile</phase> <goals> <goal>copy-resources</goal> </goals> <configuration> <encoding>UTF-8</encoding> <outputDirectory>src/main/webapp/WEB-INF/</outputDirectory> <resources> <resource> <filtering>true</filtering> <directory>src/main/build/</directory> <includes> <include>web.xml</include> </includes> </resource> </resources> </configuration> </execution> </executions> </plugin> </plugins></build>
0 0
- 使用Maven管理spring环境的profile定义
- Maven与Spring profile的结合使用
- Apache Maven 使用 profile 和 filtering 实现多种环境下的资源配置管理(属性过滤)
- Apache Maven 使用 profile 和 filtering 实现多种环境下的资源配置管理
- Apache Maven 使用 profile 和 filtering 实现多种环境下的资源配置管理
- Apache Maven 使用 profile 和 filtering 实现多种环境下的资源配置管理(属性过滤)
- Apache Maven 使用 profile 和 filtering 实现多种环境下的资源配置管理
- Apache Maven 使用 profile 和 filtering 实现多种环境下的资源配置管理(属性过滤)
- 使用Maven和Spring的profile功能实现不同运行环境的无缝切换
- 多环境支持-Maven和Spring的Profile
- Maven Profile的使用
- maven profile的使用
- maven profile的使用
- maven profile的使用
- maven profile的使用
- maven profile的使用
- maven profile的使用
- maven profile的使用
- ASP.NET 邮件发送 System.Net.Mail
- Java_jdbc 基础笔记之十四 数据库连接(元数据)
- java中如何使用任务调度
- openfire 优化
- Javascript闭包——懂不懂由你,反正我是懂了
- 使用Maven管理spring环境的profile定义
- Java 异常处理 理解
- getHibernateTemplate 批量添加数据及简单测试
- 【C++】返回单链表的第k个结点
- request和response的中文乱码问题
- 分离 结构 表现和行为
- SVG小记——入门,clipPath
- iOS 中GET 和 POST 请求
- 实现Material风格的滑动刷新Swipe to Refresh