[英]Can't start with profiles in spring + maven + tomcat
I need to use profiles with spring. 我需要在弹簧上使用轮廓。 I use local Tomcat. 我使用本地Tomcat。 There is maven project, so, in pom.xml I added: 有maven项目,因此在pom.xml中添加了:
<profiles>
<profile>
<id>dev</id>
<activation>
<property>
<name>spring.profiles.active</name>
<value>dev</value>
</property>
</activation>
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.11</version>
</dependency>
</dependencies>
</profile>
<profile>
<id>at1</id>
<activation>
<activeByDefault>true</activeByDefault>
<property>
<name>spring.profiles.active</name>
<value>at1</value>
</property>
</activation>
</profile>
</profiles>
and in application.properties added spring.profiles.active=${activatedProperties} note: spring.profiles.active=@activatedProperties@ tried already too 并在application.properties中添加了spring.profiles.active = $ {activatedProperties}注意:spring.profiles.active = @ activatedProperties @也已经尝试过
and there is two files application-at1.properties and application-dev.properties 有两个文件application-at1.properties和application-dev.properties
When build war with -Dspring.profiles.active=dev there is error message - params from this files not found. 使用-Dspring.profiles.active = dev建立战争时,会出现错误消息-找不到此文件的参数。
My tomcat customizations are: 我的tomcat定制是:
Can't tell exactly where you are but seems to me that you're using a property place holder, Spring Boot is not picking up a profile because the placeholder actually has no value. 无法确切说出您的位置,但在我看来您正在使用属性占位符,Spring Boot不会选择配置文件,因为占位符实际上没有任何价值。
You can configure this in the following way: 您可以通过以下方式进行配置:
Using Property Placeholders: 使用属性占位符:
application.properties application.properties
spring.profiles.active=${activatedProperties}
pom.xml 的pom.xml
<property>
<name>activatedProperties</name>
<value>dev</value>
</property>
Just specify the runtime argument 只需指定运行时参数
Remove property from pom.xml and adjust your application.properties with some default value or don't specify it at all 从pom.xml中删除属性,并使用一些默认值调整您的application.properties或根本不指定它
spring.profiles.active=at1 #you can remove this line if you want.
Then run-war with argument -Dspring.profiles.active=dev
然后使用-Dspring.profiles.active=dev
参数运行
Working with Maven Profiles 使用Maven配置文件
You can run maven with a -P dev
to make sure that the goal is executed with the correct profile. 您可以使用-P dev
运行maven,以确保使用正确的配置文件执行目标。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.