欢迎来到代码驿站!

JAVA代码

当前位置:首页 > 软件编程 > JAVA代码

maven profile实现多环境配置的示例

时间:2021-03-19 09:45:59|栏目:JAVA代码|点击:

环境:eclipse + spring mvc + maven

1、直接看图,把数据库的配置单独拿出来放在了resources_env目录下,三个不同环境参数不同,

2,在pom文件中添加配置 

<profiles> 
    <profile> 
      <!-- 开发环境 --> 
      <id>dev</id> 
      <properties> 
        <env>dev</env>
      </properties> 
      <activation> 
        <!-- 默认激活该profile节点-->
        <activeByDefault>true</activeByDefault> 
      </activation> 
      <build>
        <resources>
          <resource>
            <directory>src/main/resources_env/dev</directory>
          </resource>
          <resource>
            <directory>src/main/resources</directory>
          </resource>
        </resources>
      </build>
    </profile> 
    <profile> 
      <!-- 测试环境 --> 
      <id>qa</id> 
      <properties> 
        <env>qa</env>
      </properties>
      <build>
        <resources>
          <resource>
            <directory>src/main/resources_env/qa</directory>
          </resource>
          <resource>
            <directory>src/main/resources</directory>
          </resource>
        </resources>
      </build>
    </profile>  
    <profile>
      <!-- 生产环境 -->
      <id>online</id> 
      <properties>
        <env>online</env>
      </properties> 
      <build>
        <resources>
          <resource>
            <directory>src/main/resources_env/online</directory>
          </resource>
          <resource>
            <directory>src/main/resources</directory>
          </resource>
        </resources>
      </build>
    </profile> 
  </profiles>

说明:这个resources里面的路径对应上面文件路径,resources里面所有的配置加上各自环境的配置,

在引用jdbc.pro的地方如下:在datasource.xml中,

还有 新增的 evn那个包下面的所有文件都需要设置为资源文件,这个不必说 直接看图

3,maven设置要使用的环境:

项目右键-->maven-->Select Maven profiles ,选择一个环境,修改最好清理一下项目才生效,我之前没清理,发现没起作用。

 

4、然后运行项目就是你选择的环境了,或者直接导出war包,

  其他的多环境配置同。

上一篇:关于idea更新到2020.2.3无法创建web项目原因 library is not specified

栏    目:JAVA代码

下一篇:详解Struts2中配置默认Action的方法

本文标题:maven profile实现多环境配置的示例

本文地址:http://www.codeinn.net/misctech/83854.html

推荐教程

广告投放 | 联系我们 | 版权申明

重要申明:本站所有的文章、图片、评论等,均由网友发表或上传并维护或收集自网络,属个人行为,与本站立场无关。

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:914707363 | 邮箱:codeinn#126.com(#换成@)

Copyright © 2020 代码驿站 版权所有