Java Maven配置文件未激活,默认配置文件除外
我正在开发一个spring启动应用程序。我的POM中有两个配置文件,但是当我尝试使用clean install-Pdev构建项目时,它不会反映application.properties中的更改,它只会反映我在其中一个配置文件中使用'activeByDefault'标记时的更改Java Maven配置文件未激活,默认配置文件除外,java,maven,spring-boot,pom.xml,maven-plugin,Java,Maven,Spring Boot,Pom.xml,Maven Plugin,我正在开发一个spring启动应用程序。我的POM中有两个配置文件,但是当我尝试使用clean install-Pdev构建项目时,它不会反映application.properties中的更改,它只会反映我在其中一个配置文件中使用'activeByDefault'标记时的更改 <profiles> <profile> <id>dev</id> <properties> <activatedProp
<profiles>
<profile>
<id>dev</id>
<properties>
<activatedProperties>dev</activatedProperties>
</properties>
</profile>
<profile>
<id>release</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<properties>
<activatedProperties>release</activatedProperties>
</properties>
</profile>
</profiles>
发展
发展
释放
假的
释放
如果我运行的是clean install-Pdev,我会在application.properties中得到它。
activatedProperties=@activatedProperties@
如果我将设置为true
,那么我将在application.properties中获取该值。
activatedProperties=发布
令人沮丧的是,我无法使用其他配置文件。请添加您的应用程序。属性
spring.profiles.active=@activatedProperties@
spring.profiles.active=dev
如果Maven在运行时找不到包含application.properties文件的目录,则需要设置Maven资源插件来过滤该目录
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
...
</build>
注意:Maven配置文件和Spring配置文件是不同的东西 为什么您认为需要
true
staff?因为这样可以将标记中定义的属性插入到资源目录中的任何文件中。spring.profiles.active=@activatedProperties@in application.properties将在没有true staff的情况下被注入。您尝试过吗?我想你想说的是东西而不是员工,对吧?我试过了,没有资源标签。是的,很抱歉。我想你需要在-P和配置文件名之间加一个空格。@JJF有空格或没有空格都是一样的。