所以我正在构建一个 spring boot web 应用程序,打包为 war,并部署到 tomcat 应用程序服务器。
我在 tomcat 的 pom.xml 中有以下依赖项:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
需要提供此依赖项的范围,以便能够将其部署到 tomcat 实例。但是,当我想通过 spring boot CLI 或通过 IntelliJ 的默认 spring boot 运行配置运行 war 时,我需要删除 <scope>provided</scope>
以便它运行嵌入式 tomcat。
我的问题是,是否有某种方法可以根据 Activity 的 spring 配置文件或其他方法有条件地提供依赖关系?
最佳答案
在您的具体情况下,您可以这样做: 在使用嵌入式 tomcat 运行 spring-boot 的依赖项中:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</dependency>
并在配置文件中部署到tomcat下
<profile>
<id>tomcat</id>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
</profile>
之后,为特定的配置文件构建
mvn clean install -Ptomcat
关于java - 根据 Activity 的 Spring 配置文件提供一个 Maven 依赖项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42299263/