根据活动的弹簧配置文件提供Maven依赖关系 [英] Make a maven dependency provided based on active spring profile

查看:130
本文介绍了根据活动的弹簧配置文件提供Maven依赖关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我正在构建一个Spring Boot Web应用程序,打包作为战争,并部署到tomcat应用程序服务器中.

So I am building a spring boot web application, packaging as a war, and deploying to a tomcat application server.

我的tomcat的pom.xml中具有以下依赖项:

I have the following dependency in my pom.xml for tomcat:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-tomcat</artifactId>
    <scope>provided</scope>
</dependency>

需要提供此依赖项的范围,以便能够将其部署到tomcat实例.但是,当我想通过spring boot CLI或IntelliJ的默认spring boot run配置运行战争时,我需要删除<scope>provided</scope>才能运行嵌入式tomcat.

The scope of this dependency needs to be provided in order to be able to deploy it to a tomcat instance. However, when I want to run the war via the spring boot CLI or via IntelliJ's default spring boot run configuration, I need to remove the <scope>provided</scope> in order for it to run the embedded tomcat.

我的问题是,是否有某种方法可以基于活动的弹簧轮廓或其他方法有条件地提供依赖关系?

My question is, is there some way to make the dependency conditionally provided based on an active spring profile, or some other method?

推荐答案

您无法通过spring配置文件控制依赖项.但是,您可以通过maven配置文件控制弹簧配置文件,它可以解决您的问题.

You can't control dependencies via spring profiles. However you can control spring profiles by maven profiles and it can solve your problem.

您可以在应用程序中声明几个Maven概要文件,并为每个概要文件提供不同的依赖关系集. 然后,您可以配置Maven配置文件以使用特定的弹簧配置文件. 看看关于Maven配置文件以及这种配置的示例在该线程中

You can declare several maven profiles in your application and provide different set of dependencies for each of them. Then you can configure maven profiles to use particular spring profile. Take a look on maven profiles and an example of such configuration in this thread

这篇关于根据活动的弹簧配置文件提供Maven依赖关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆