java - 排除基于 maven 配置文件的嵌入式服务器
问题描述
我在 pom.xml 中定义了两个不同的配置文件(dev 和 prod)。我不想在使用 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>
提前致谢。
解决方案
尝试这样的事情:
<!-- Other profiles -->
<profile>
<id>prod</id>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
</profile>
<!-- Other profiles -->
</profiles>
但是,您必须小心应用程序打包。也许您需要将 fat jar(用于开发环境)切换为生产环境的战争(因为您将排除嵌入式服务器)。
推荐阅读
- javascript - 如何使用 Vega/Vega lite 创建响应式饼图?
- qt - 单击“运行”时,QtCreator 卡在启动 .exe 文件上
- linux - 我将可执行文件放在树莓派 4 的启动中,当我在以相同名称运行的终端 2 进程中运行 top 命令时,如何避免这个问题?
- amazon-web-services - 更新控制器中的 Http 调用时如何自动更新 serverless.template 文件?
- mysql - 由于语法错误,无法使用设置触发器
- python-3.x - 解析命名空间 xml 生成 AttributeError: 'str' object has no attribute 'text'
- angular - 如何在运行函数Angular之前等待从Firestore加载数据
- arrays - React Material-Table - 如何在从获取的数组呈现的单元格之间添加逗号?
- monitoring - Windows 服务集成后如何在 New relic 仪表板中查找有关服务的详细信息
- ansible - 如何使用ansible替换json文件中键的值