我使用Maven作为我的构建工具。对于SpringBoot中的配置文件管理,我使用了yml文件。
对于我的SpringBoot应用程序,我设置了以下应用程序-*.yml文件:
application.yml
application-local.yml
application-foobar.yml我对应的pom.xml配置文件配置:
<profiles>
<profile>
<id>local</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<activatedProperties>local</activatedProperties>
</properties>
</profile>
<profile>
<id>foobar</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<properties>
<activatedProperties>foobar</activatedProperties>
</properties>
</profile>
</profiles>每当我尝试通过Maven打包或运行我的应用程序时:
> mvn package -P <any configured profile>
> mvn spring-boot:run -P <any configured profile>该应用程序运行,但它只运行回退到默认配置文件(application.yml)。每次我尝试在我配置的任何配置文件下运行该应用程序时,都会得到以下日志条目:
: No active profile set, falling back to default profiles: default我似乎在互联网上找不到任何关于这个问题的明确信息。任何帮助都将不胜感激。谢谢!
发布于 2020-08-28 00:41:27
Maven构建配置文件和Spring bean配置文件是两个完全不同的概念,它们恰好使用相同的名称,但并不相互作用。
您使用<profiles></profiles>显示的XML配置了Maven build profiles,但不会对Spring bean配置文件产生任何影响。
根据Spring Framework documentation on activating a profile和Spring Boot documentation on passing arguments when running an application,您可以在使用Maven运行应用程序时选择活动的Spring bean配置文件,命令如下:
> mvn spring-boot:run -Dspring-boot.run.jvmArguments="-Dspring.profiles.active=local"https://stackoverflow.com/questions/63608798
复制相似问题