zoukankan      html  css  js  c++  java
  • 使用spring profile实现多环境切换

    第一步:

    applicationContext.xml

        <!--环境配置开始-->
        <beans profile="production">
            <context:property-placeholder
                    ignore-resource-not-found="true" location="classpath:config.prod.properties"/>
        </beans>
    
        <beans profile="development">
            <context:property-placeholder
                    ignore-resource-not-found="true" location="classpath:config.dev.properties"/>
        </beans>

    第二步:

    配置web.xml

        <context-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/applicationContext*.xml</param-value>
        </context-param>
    
        <!--测试环境-->
        <context-param>
            <param-name>spring.profiles.default</param-name>
            <param-value>development</param-value>
        </context-param>
    
        <!--生产环境-->
        <!--<context-param>
            <param-name>spring.profiles.default</param-name>
            <param-value>prod</param-value>
        </context-param>-->

    第三步:

    其重点难点:

    Windows系统中,修改tomcat  start.bat文件,在第一行加入:

    SET JAVA_OPTS="-Dspring.profiles.active=prod"

    Linux 系统中,修改tomcat  catlina.sh文件,在第一行加入:

    CATALINA_OPTS="$CATALINA_OPTS -Dspring.profiles.active="prod""

    或者

    JAVA_OPTS="-Dspring.profiles.active="production""

    Window 系统中查看是否设置成功:

    打开%jdk_home%in 中的 jvisualvm.exe  界面即可:

  • 相关阅读:
    hadoop节点的增删
    hadoop集群搭建
    主从配置
    CentOS7ssh互信
    Java根据视频的URL地址,获取视频时长
    Mybatis-plus使用@Select注解使用IN查询不出数据的问题
    洗牌算法
    1525
    SpringBoot+Quartz+MySQL实现分布式定时任务
    微信小程序授权登录解密失败问题
  • 原文地址:https://www.cnblogs.com/hero123/p/10861693.html
Copyright © 2011-2022 走看看