浅谈xml配置spring profiles的几个注意点
作者:bluehtt 发布时间:2022-07-20 15:20:09
标签:xml,spring,profiles
先贴正确配置
<?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:aop="http://www.springframework.org/schema/aop"
xmlns:task="http://www.springframework.org/schema/task"
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/aop http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<aop:aspectj-autoproxy></aop:aspectj-autoproxy>
<task:annotation-driven/>
<import resource="spring-datasource.xml"/>
<import resource="spring-hessian-server.xml"/>
<import resource="spring-remoting-dis.xml"/>
<import resource="spring-remoting-worldeye.xml"/>
<import resource="spring-activemq.xml"/>
<import resource="spring-cxf-client.xml"/>
<!-- 开发配置 -->
<beans profile="dev">
<context:property-placeholder location="classpath:config/application.properties, classpath:config/application-dev.properties"/>
<import resource="spring-hadoop-dev.xml"/>
</beans>
<!-- 测试配置 -->
<beans profile="test">
<context:property-placeholder location="classpath:config/application.properties, classpath:config/application-prd.properties, classpath:config/application-test.properties"/>
<import resource="spring-hadoop-test.xml"/>
</beans>
<!-- 线上配置 -->
<beans profile="prd">
<context:property-placeholder location="classpath:config/application.properties, classpath:config/application-prd.properties"/>
<import resource="spring-hadoop.xml"/>
</beans>
</beans>
一. xml标签的xsd版本
spring-beans.xsd 文件不要指定版本,也可以使用高版本(起码是3.1),原因是 spring profile 是3.1版本开始的。
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
......
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
二. dispatcherServlet文件配置
web.xml中配置了 DispatcherServlet 的 contextConfigLocation,需要在 spring-dispatch.xml 添加 spring profile 的配置,配置项同上。
<!-- profile配置 -->
<context-param>
<param-name>spring.profiles.active</param-name>
<param-value>prd</param-value>
</context-param>
<!-- Spring配置 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:config/spring/spring-context.xml
classpath:config/spring/spring-security.xml
</param-value>
</context-param>
......
<!-- Spring Dispatcher配置 -->
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:config/spring/spring-hessian-server.xml
classpath:config/spring/spring-dispatch.xml
classpath:config/spring/spring-security.xml
</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
来源:https://segmentfault.com/a/1190000019853729


猜你喜欢
- 概述附件,指随同文件发出的有关文件或物品。在PDF文档中,我们可以添加同类型的或其他类型的文档作为附件内容,而PDF中附件也可以分为两种存在
- 下面的例子为使用自定义的列表适配器来显示列表。 View Code import android.os.Bundle; import and
- C#实现委托namespace Delegate{ delegate void DGSayiHi(string n
- 本文实例为大家分享了Flutter底部导航栏的实现代码,供大家参考,具体内容如下老规格,先看图:程序主结构如下:1.在程序主入口文件main
- 最近刚完成一个简单的网络爬虫,开始的时候很迷茫,不知道如何入手,后来发现了很多的资料,不过真正能达到我需要,有用的资料--代码很难找。所以我
- 这篇文章主要介绍了设计模式在Spring框架中的应用汇总,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的
- 本文实例讲述了C#使用WebService结合jQuery实现无刷新翻页的方法。分享给大家供大家参考。具体如下:1. 首先创建数据库、表Ar
- C#程序自删除核心实现方法就是调用 cmd 传入命令行,等待几秒之后删除文件;应用程序在运行时,是不能将 exe 文件进行删除的。但是可以将
- 首先让大家有个全局的认识,直接上个项目,看看仅仅通过这几行代码,竟然就能完成如此强悍的功能。下篇再仔细讲讲为什么要这么写。效果图:实现了三个
- mybatis映射和实际类型不一致项目今天出现个问题,在dao中定义了一个查询,方法的返回值是map并定义了泛型都是String类型,可是方
- 什么是Java垃圾回收器Java垃圾回收器是Java虚拟机(JVM)的三个重要模块(另外两个是解释器和多线程机制)之一,为应用程序提供内存的
- 安卓虽然已经成为了移动设备第一操作系统,且影响力也延伸到了汽车和tv端,不过对于谷歌来说,需要依靠Java来做安卓开发一直是一个心病,因为O
- 成功本文通过java语言实现ECC+AES混合加密。ECC加密算法具有密钥分配与管理简单,安全强度高等优点,AES的加密算法具有速度快,强度
- 概述ZXing 是一个开源 Java 类库用于解析多种格式的 1D/2D 条形码。目标是能够对QR编码、Data Matrix、UPC的1D
- 需要为项目提供一套畸变校正的算法,由于需要大量的矩阵运算,考虑到效率和适时性,使用JNI开发,希望把有关数组短阵的处理的变换全部放入C语言中
- 前言JAVA中在运用数组进行排序功能时,一般有四种方法:快速排序法、冒泡法、选择排序法、插入排序法。本文就给大家介绍了关于最简单易懂的jav
- 从功能上说,可以分为两部分,分布式功能和数据功能。分布式功能主要是节点集群及集群附属功能如restful借口、集群性能检测功能等,数据功能主
- 本文实例讲述了Android判断网络类型的方法。分享给大家供大家参考,具体如下:判断网络类型是wifi,还是3G,还是2G网络,对不同的网络
- 本文实例讲述了Android编程动态按钮实现方法。分享给大家供大家参考,具体如下:第一种: 该方法通过onTouch来实现,btn3 = (
- 如何获取yml、properties参数1、使用@Value()注解1.1 配置数据如:在properties.yml文件配置如下数据mes