【发布时间】:2019-12-12 01:52:46
【问题描述】:
我想在 Maven 中组合一个环境,我想根据激活的 Maven 配置文件累积激活多个弹簧配置文件。
目前我的 pom.xml 的相关部分如下所示:
<profiles>
<profile>
<id>local-db-development</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<dependencies>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
</dependencies>
<properties>
<spring.profiles.active>local-db</spring.profiles.active>
</properties>
</profile>
<profile>
<id>live-db-development</id>
<dependencies>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>
</dependencies>
<properties>
<spring.profiles.active>live-db</spring.profiles.active>
</properties>
</profile>
<profile>
<!--
If active, the user authentication will be through LDAP and AD,
Database auth will be used otherwise
-->
<id>ldap-authentication</id>
<properties>
<spring.profiles.active>ldap-authentication</spring.profiles.active>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-ldap</artifactId>
</dependency>
<dependency>
<groupId>org.apache.directory.server</groupId>
<artifactId>apacheds-server-jndi</artifactId>
<version>1.5.5</version>
</dependency>
</dependencies>
</profile>
</profiles>
我的问题是,当我激活 ldap-authentication 配置文件时,只有相关的 spring 配置文件会处于活动状态,而不考虑任何 *-db 配置文件。
我想这样做,以便我可以激活 ldap-authentication 和 local-db maven 配置文件,然后应该激活两个相关的 spring 配置文件,或者当我激活时让我们说 maven 中的 ldap-authentication 和 live-db ,那么这 2 个弹簧配置文件将处于活动状态。
我还没有真正找到连接弹簧轮廓的方法,所以如果你知道得更好,请告诉我。
提前致谢
【问题讨论】:
-
“这样我就可以点击 ldap-authentication 和 local-db 然后”点击 ??请详细说明你的意思。您在应用程序范围内单击,而不是在运行诸如
mvn之类的可执行文件时单击。 -
已编辑,我希望现在更清楚了。 “点击”是指我在 IntelliJ 中激活 maven 配置文件时的操作(如点击复选框)
-
你不应该那样做。您应该构建一个工件,而不是为不同的配置文件构建一个工件。 Maven 配置文件!= 弹簧配置文件。
-
我知道,这是我的问题。我想这样做,以便每个活动的 Maven 配置文件激活相关的弹簧配置文件,而不会相互覆盖。
-
您能否详细说明为什么我不应该这样做,或者有什么更好的方法来解决我的问题?哦,这个问题的重点是我想构建一个具有多个活动弹簧轮廓的工件