【发布时间】:2020-04-17 23:48:56
【问题描述】:
我在 pom.xml 中定义了两个不同的配置文件(dev 和 prod)。我不想在使用 prod 配置文件构建项目时包含嵌入式服务器。我知道即使我不从 jar 中排除嵌入式服务器,我也可以将它部署到其他服务器上。
我已经检查了两个如何使用下面的 sn-p 排除 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>
提前致谢。
【问题讨论】:
-
我不明白您为什么要使用 maven 配置文件而不是 Spring Boot 配置文件来实现您的目的......如果您需要制作一个带有嵌入式服务器的服务器和一个没有您应该制作两个不同的它的工件,也可以非常干净地处理不同的依赖关系。我强烈反对使用具有不同依赖项的配置文件。如果您想构建版本,这将导致问题...
-
@khmarbaise 我使用了 maven 配置文件,因为我想在打包期间根据配置文件排除 application.properties。我相信 spring 配置文件和 maven 配置文件是不同的东西。如果我错了,请纠正我。
标签: java spring-boot maven pom.xml embedded-tomcat