maven的多环境打包部署与web.xml整合

背景:
由于项目处于变更频发阶段,经常需要同时在dev、test、demo、uat环境打包发布,由于现在没有绑定域名,在做单点登录的时候,每次打包都需要手动修改web.xml中的ip地址,十分麻烦,并且非常容易出错。

如何解决此类问题
1、在pom的profile中添加如下代码:新增cas.serverLoginUrl、cas.serverName、cas.serverUrlPrefix三个properties


<profiles>
    <profile>
        <id>development</id>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
        <properties>
            <profiles.active>dev</profiles.active>
            <mybatis.log>ERROR</mybatis.log>
            <log.path>/opt/dev/</log.path>
            <cas.serverLoginUrl>http://10.1.1.1</cas.serverLoginUrl>
            <cas.serverName>http://10.1.1.1</cas.serverName>
            <cas.serverUrlPrefix>http://10.1.1.1</cas.serverUrlPrefix>
        </properties>
    </profile>
    <profile>
        <id>test</id>
        <properties>
            <profiles.active>test</profiles.active>
            <mybatis.log>ERROR</mybatis.log>
            <cas.serverLoginUrl>http://10.1.1.1</cas.serverLoginUrl>
            <cas.serverName>http://10.1.1.1</cas.serverName>
            <cas.serverUrlPrefix>http://10.1.1.1</cas.serverUrlPrefix>
        </properties>
        </properties>
    </profile>
    <profile>
        <id>demo</id>
        <properties>
            <profiles.active>demo</profiles.active>
            <mybatis.log>ERROR</mybatis.log>
            <cas.serverLoginUrl>http://10.1.1.1</cas.serverLoginUrl>
            <cas.serverName>http://10.1.1.1</cas.serverName>
            <cas.serverUrlPrefix>http://10.1.1.1</cas.serverUrlPrefix>
        </properties>
    </profile>
    <profile>
        <id>uat</id>
        <properties>
            <profiles.active>uat</profiles.active>
            <mybatis.log>ERROR</mybatis.log>
            <cas.serverLoginUrl>http://10.1.1.1</cas.serverLoginUrl>
            <cas.serverName>http://10.1.1.1</cas.serverName>
            <cas.serverUrlPrefix>http://10.1.1.1</cas.serverUrlPrefix>
        </properties>
    </profile>
    <profile>
        <id>pre</id>
        <properties>
            <profiles.active>pre</profiles.active>
            <mybatis.log>ERROR</mybatis.log>
        </properties>
    </profile>
    <profile>
        <id>production</id>
        <properties>
            <profiles.active>pro</profiles.active>
            <mybatis.log>ERROR</mybatis.log>
        </properties>
    </profile>
</profiles>

2.在web module的pom中,新增过滤web资源配置

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <version>2.1.1</version>
    <configuration>
        <webResources>
            <resource>
                <directory>src/main/webapp</directory>
                <filtering>true</filtering>
            </resource>
        </webResources>
    </configuration>
</plugin>

3.在web.xml中用占位符替换

<filter>
   <filter-name>CASFilter</filter-name>
   <filter-class>com.ezubo.global.om.web.filter.LoginFilter</filter-class>
   <init-param>
      <param-name>casServerLoginUrl</param-name>
      <param-value>${cas.serverLoginUrl}</param-value>
   </init-param>
   <init-param>
      <param-name>serverName</param-name>
      <param-value>${cas.serverName}</param-value>
   </init-param>
   <init-param>
      <param-name>noFilterUrl</param-name>
      <param-value>*.js</param-value>
   </init-param>
</filter>

4.打包时加入-P,如demo环境 mvn clean package -DskipTests -Pdemo

  • 1
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值