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


    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>
  • 相关阅读:
    Redis(二)
    Redis(一)
    MyBatis--一级二级缓存
    MySQL优化
    HashMap
    ArrayList
    常用框架注解说明
    Linux常用基础命令
    SpringCloud--gateway路由配置
    JetBrains系列软件的插件安装
  • 原文地址:https://www.cnblogs.com/wsy0202/p/11842091.html
Copyright © 2020-2023  润新知