我需要在弹簧上使用轮廓。我使用本地Tomcat。 有一个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>
并在application.properties中添加了spring.profiles.active = $ {activatedProperties} 注意:spring.profiles.active = @ activatedProperties @也已经尝试过
,有两个文件application-at1.properties和application-dev.properties
使用-Dspring.profiles.active = dev建立战争时,出现错误消息-找不到此文件中的参数。
我的tomcat自定义项是:
答案 0 :(得分:1)
无法确切地说出您的位置,但在我看来您正在使用属性占位符,Spring Boot不会选择配置文件,因为占位符实际上没有任何价值。
您可以通过以下方式进行配置:
使用财产占位符:
application.properties
spring.profiles.active=${activatedProperties}
pom.xml
<property>
<name>activatedProperties</name>
<value>dev</value>
</property>
只需指定运行时参数
从pom.xml中删除属性,并使用一些默认值调整您的application.properties或根本不指定它
spring.profiles.active=at1 #you can remove this line if you want.
然后使用参数-Dspring.profiles.active=dev
进行战争
使用Maven配置文件
您可以使用-P dev
运行maven,以确保使用正确的配置文件执行目标。