利用spring的profile切换不同的环境

1.profile简单实用-简单暴力才是最好的

 我们就简单地用一下,先不考虑和maven的集成使用,就可以解决烦人的事情。
[html]  view plain  copy
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <beans xmlns="http://www.springframework.org/schema/beans"  
  3.     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"  
  4.     xmlns:aop="http://www.springframework.org/schema/aop"  
  5.     xsi:schemaLocation="http://www.springframework.org/schema/beans   
  6.     http://www.springframework.org/schema/beans/spring-beans.xsd   
  7.     http://www.springframework.org/schema/context   
  8.     http://www.springframework.org/schema/context/spring-context.xsd   
  9.     http://www.springframework.org/schema/aop   
  10.     http://www.springframework.org/schema/aop/spring-aop.xsd">  
  11.   
  12.     <!-- 自动扫描 -->  
  13. <!--     <context:component-scan base-package="com.wei" /> -->  
  14.     <import resource="spring-dao.xml" />  
  15.     <import resource="spring-service.xml" />  
  16.     <import resource="spring-mvc.xml" />  
  17.     <import resource="spring-cxf.xml" />  
  18.     <beans profile="dev"  >  
  19.         <context:property-placeholder location="classpath*:jdbc-dev.properties" />  
  20.     </beans>  
  21.     <beans profile="sit"  >  
  22.         <context:property-placeholder location="classpath*:jdbc-sit.properties" />  
  23.     </beans>  
  24. </beans>  

我的配置如上,web.xml的配置如下
[html]  view plain  copy
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  3.     xmlns="http://java.sun.com/xml/ns/javaee"  
  4.     xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"  
  5.     version="3.0">  
  6.   
  7.     <display-name>wei-web</display-name>  
  8.     <!-- Spring和mybatis的配置文件 -->  
  9.     <context-param>  
  10.         <param-name>contextConfigLocation</param-name>  
  11.         <param-value>classpath:spring-context.xml</param-value>  
  12.     </context-param>  
  13.     <!-- 切换环境 -->  
  14.     <context-param>    
  15.         <param-name>spring.profiles.active</param-name>    
  16.         <param-value>sit</param-value>    
  17.     </context-param>    
  18.     <!-- 编码过滤器 -->  
  19.     <filter>  
  20.         <filter-name>encodingFilter</filter-name>  
  21.         <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>  
  22.         <async-supported>true</async-supported>  
  23.         <init-param>  
  24.             <param-name>encoding</param-name>  
  25.             <param-value>UTF-8</param-value>  
  26.         </init-param>  
  27.     </filter>  
  28.     <filter-mapping>  
  29.         <filter-name>encodingFilter</filter-name>  
  30.         <url-pattern>/*</url-pattern>  
  31.     </filter-mapping>  
  32.     <!-- Spring监听器 -->  
  33.     <listener>  
  34.         <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>  
  35.     </listener>  
  36.     <!-- 防止Spring内存溢出监听器 -->  
  37.     <listener>  
  38.         <listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class>  
  39.     </listener>  
  40.   
  41.     <!-- Spring MVC servlet -->  
  42.     <servlet>  
  43.         <servlet-name>SpringMVC</servlet-name>  
  44.         <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>  
  45.         <init-param>  
  46.             <param-name>contextConfigLocation</param-name>  
  47.             <param-value>classpath:spring-mvc.xml</param-value>  
  48.         </init-param>  
  49.         <load-on-startup>1</load-on-startup>  
  50.         <async-supported>true</async-supported>  
  51.     </servlet>  
  52.     <servlet-mapping>  
  53.         <servlet-name>SpringMVC</servlet-name>  
  54.         <!-- 此处可以可以配置成*.do,对应struts的后缀习惯 -->  
  55.         <url-pattern>/</url-pattern>  
  56.     </servlet-mapping>  
  57.     <!-- cxf -->  
  58.     <servlet>  
  59.         <servlet-name>cxf</servlet-name>  
  60.         <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>  
  61.         <init-param>  
  62.             <param-name>config-location</param-name>  
  63.             <param-value>classpath:spring-cxf.xml</param-value>  
  64.         </init-param>  
  65.         <load-on-startup>2</load-on-startup>  
  66.     </servlet>  
  67.   
  68.     <servlet-mapping>  
  69.         <servlet-name>cxf</servlet-name>  
  70.         <url-pattern>/rest/*</url-pattern>  
  71.     </servlet-mapping>  
  72.     <welcome-file-list>  
  73.         <welcome-file>/index.jsp</welcome-file>  
  74.     </welcome-file-list>  
  75. </web-app>   
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值