我们在线上开发的时候不免要用到多个环境开发,一种的开发环境,一种是测试环境,还有就是生产环境,我们在开发的时候不可能直接用线上的环境进行修改,因为这样会带来很多无可预知的麻烦,所以我们要进行环境隔离~
<build> </build>
里面添加下面参数,设置Maven多环境的时候资源是通用的。
<resources>
<resource>
<directory>src/main/resources.${deploy.type}</directory>
<excludes>
<exclude>*.jsp</exclude>
</excludes>
</resource>
<resource>
<directory>src/main/resources</directory>
</resource>
</resources>
如:
![img_4269d9ec8059c7bef754b5c7a472f2ac.png](https://yqfile.alicdn.com/img_4269d9ec8059c7bef754b5c7a472f2ac.png?x-oss-process=image/resize,w_1400/format,webp)
image.png
在 </build>
和</project>
之间配置下面参数:
<profiles>
<profile>
<id>dev</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<deploy.type>dev</deploy.type>
</properties>
</profile>
<profile>
<id>beta</id>
<properties>
<deploy.type>beta</deploy.type>
</properties>
</profile>
<profile>
<id>prod</id>
<properties>
<deploy.type>prod</deploy.type>
</properties>
</profile>
</profiles>
如:
![img_0fa60ef240d76d8c48207c66ccd486b9.png](https://yqfile.alicdn.com/img_0fa60ef240d76d8c48207c66ccd486b9.png?x-oss-process=image/resize,w_1400/format,webp)
image.png
上面的<deploy.type>
对应着最首先添加jsp
里面的${deploy.type}
![img_cffe58b03368095d6a55a2c3202d18da.png](https://yqfile.alicdn.com/img_cffe58b03368095d6a55a2c3202d18da.png?x-oss-process=image/resize,w_1400/format,webp)
image.png
配置完成之后,我们点击IDEA的Maven Project
就会发现有对应的参数添加进去了~
在配置多环境的时候我们给dev
设置为true
,所以也就默认选中为dev
了~
<activation>
<activeByDefault>true</activeByDefault>
</activation>
![img_873fbe51724eb79ba622a3a586e362a5.png](https://yqfile.alicdn.com/img_873fbe51724eb79ba622a3a586e362a5.png?x-oss-process=image/resize,w_1400/format,webp)
image.png