• 根据环境配置获取不同的配置文件


    1.建立一个配置文件设置环境变量

     2.新建一个xml文件根据环境变量获取不同的配置文件

     代码:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
            "http://www.springframework.org/dtd/spring-beans.dtd">
    <beans>
        <bean class="shelper.spring.ext.PropertyPlaceholderConfigurer">
            <property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" />
            <property name="ignoreResourceNotFound" value="true" />
            <property name="rootLocation">
                <value>classpath:properties/env_pro.properties</value>
            </property>
            <property name="childLocations">
                <list>
                    <value>classpath:/properties/${STG}/persion.properties</value>
                    <value>classpath:/properties/${STG}/cmdc.properties</value>
                </list>
            </property>
    
        </bean>
    </beans>

    3.配置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: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/context
        http://www.springframework.org/schema/context/spring-context.xsd">
        <context:component-scan base-package="net.bill99"></context:component-scan>
    
        <!--引入配置文件-->
        <import resource="classpath:context/envLoad.xml"></import>
    
        <!--引入bean文件-->
        <import resource="classpath:spring/*.xml"></import>
    </beans>
  • 相关阅读:
    Vim作者创造新编程语言Zimbu
    Google Maps API编程资源大全
    好网收集的地址
    三种模拟自动登录和提交POST信息的实现方法
    解析VMware三种网络连接方式
    PostgreSQL 创建帐号,数据库,权限
    LINUX目录详解
    Linux流媒体服务器安装配置
    用RAMDISK来提高PostgreSQL访问速度
    PostgreSQL 集群复制方案之使用pgq和londiste工具包
  • 原文地址:https://www.cnblogs.com/wsy0202/p/11842091.html
Copyright © 2020-2023  润新知