For the time being, create an appropriate `pom.xml`
.
pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>kagamihoge</groupId>
<artifactId>asdasdf</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>asdasdf</name>
<description>Add project description here</description>
<properties>
<maven.war.filteringDeploymentDescriptors>true</maven.war.filteringDeploymentDescriptors>
</properties>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.8.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
</dependency>
</dependencies>
<profiles>
<profile>
<id>hoge</id>
<properties>
<spring_profile_value>hoge_profile</spring_profile_value>
</properties>
</profile>
</profiles>
</project>
Of the above, by setting `<maven.war.filteringDeploymentDescriptors> ... </ maven.war.filteringDeploymentDescriptors>`
, `maven-war-plugin``` will be
web.xml
It will replace the `` placeholder.
src/main/webapp/WEB-INF/web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
<context-param>
<param-name>spring.profiles.active</param-name>
<param-value>@spring_profile_value@</param-value>
</context-param>
</web-app>
Specify spring.profiles.active specified in maven profile in context-param of web.xml. In spring-boot, the maven placeholder reference is `@ ... @`
instead of `` $ {...}
`.
After that, if you do mvn package -P hoge
, the web.xml in the generated war will look like this.
web.xml
<context-param>
<param-name>spring.profiles.active</param-name>
<param-value>hoge_profile</param-value>
</context-param>
However, it is also written in How to set spring active profiles with maven profiles that I referred to. But it's not very beautiful to switch active profiles this way. This is because different wars are created for each environment, so there is less trouble if there is only one final binary.
However, even so, there are various cases in the real world, so it cannot be said that the specification via web.xml is bad.
Recommended Posts