我在 pom.xml 中定义了两个不同的配置文件(dev 和 prod)。我不想在使用产品配置文件构建项目时包含嵌入式服务器。我知道即使我不从 jar 中排除嵌入式服务器,我也可以将其部署在其他服务器上。
我已经检查了如何使用下面的代码片段排除 tomcat:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
我无法弄清楚如何根据所选配置文件排除它。以下是我的 POM.xml 的构建和配置文件属性。请指导。
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<includes>
<include>application.properties</include>
<include>application-${profileName}.properties</include>
<include>*.xml</include>
</includes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>dev</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<profileName>dev</profileName>
</properties>
</profile>
<profile>
<id>prod</id>
<properties>
<profileName>prod</profileName>
</properties>
</profile>
</profiles>
提前致谢。
最佳答案
尝试在您的配置文件中使用依赖项标签,仅包含您想要该配置文件的依赖项。
<profiles>
<profile>
<id>dev</id>
<dependencies>
// do stuff
</dependencies>
</profile>
</profiles>
关于java - 根据maven配置文件排除嵌入式服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59510378/