淺談xml配置spring profiles的幾個注意點(diǎn)
先貼正確配置
<?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"/>
<!-- 開發(fā)配置 -->
<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標(biāo)簽的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 的配置,配置項(xiàng)同上。
<!-- 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>
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
同時使用@LoadBalanced?@RefreshScope注解負(fù)載均衡失效分析
這篇文章主要為大家介紹了同時使用@LoadBalanced?@RefreshScope負(fù)載均衡失效問題分析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-02-02
淺析如何使用Swagger生成帶權(quán)限控制的API文檔
當(dāng)涉及到權(quán)限控制時,如何生成既安全又詳細(xì)的?API?文檔就成了一個關(guān)鍵問題,所以這篇文章小編就來和大家好好聊聊如何用?Swagger?來生成帶有權(quán)限控制的?API?文檔吧2025-02-02
springboot使用dubbo和zookeeper代碼實(shí)例
這篇文章主要介紹了springboot使用dubbo和zookeeper代碼實(shí)例,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下2019-11-11
詳解如何為SpringBoot Web應(yīng)用的日志方便追蹤
在Web應(yīng)用程序領(lǐng)域,有效的請求監(jiān)控和可追溯性對于維護(hù)系統(tǒng)完整性和診斷問題至關(guān)重要,SpringBoot是一種用于構(gòu)建Java應(yīng)用程序的流行框架,在本文中,我們探討了在SpringBoot中向日志添加唯一ID的重要性,需要的朋友可以參考下2023-11-11
java.lang.ArrayIndexOutOfBoundsException數(shù)組越界異常問題解決
這篇文章主要給大家介紹了關(guān)于java.lang.ArrayIndexOutOfBoundsException數(shù)組越界異常問題解決的相關(guān)資料,數(shù)組越界訪問是一個非常嚴(yán)重的問題,文中通過圖文將解決的辦法介紹的非常詳細(xì),需要的朋友可以參考下2024-01-01
Java多線程--讓主線程等待所有子線程執(zhí)行完畢在執(zhí)行
Java主線程等待所有子線程執(zhí)行完畢在執(zhí)行,其實(shí)在我們的工作中經(jīng)常的用到,本篇文章就介紹了Java多線程--讓主線程等待所有子線程執(zhí)行完畢在執(zhí)行,有需要的可以了解一下。2016-11-11
mybatis?plus配置自動create_time和update_time方式
在處理數(shù)據(jù)時,注意時間類型的轉(zhuǎn)換非常重要,不同編程環(huán)境和數(shù)據(jù)庫對時間數(shù)據(jù)的處理方式各異,因此在數(shù)據(jù)遷移或日常處理中需謹(jǐn)慎處理時間格式,個人經(jīng)驗(yàn)表明,了解常用的時間轉(zhuǎn)換函數(shù)和方法能有效避免錯誤,提高工作效率,希望這些經(jīng)驗(yàn)?zāi)転榇蠹規(guī)韼椭?/div> 2024-09-09最新評論

