背景:
由于项目处于变更频发阶段,经常需要同时在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