【发布时间】:2017-06-17 00:15:41
【问题描述】:
我在 pom.xml 中定义了三个配置文件
<profiles>
<profile>
<id>development</id>
<properties>
<activatedProperties>development</activatedProperties>
<env.identifier>dev</env.identifier>
</properties>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
<profile>
<id>qualification</id>
<properties>
<activatedProperties>qualification</activatedProperties>
<env.identifier>klif</env.identifier>
</properties>
</profile>
<profile>
<id>production</id>
<properties>
<activatedProperties>production</activatedProperties>
<env.identifier>prod</env.identifier>
</properties>
</profile>
</profiles>
我还将构建节点修改为:
<build>
<finalName>myApplication</finalName>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<executable>true</executable>
</configuration>
</plugin>
</plugins>
</build>
我创建了三个属性文件,并将此模式命名为:application-[profileId].properties。 在 application.properties 这是我定义的一般属性:
spring.profiles.active=@activatedProperties@指定 spring boot 使用哪个配置文件。 我还为我的日志文件定义了一个文件,如下所示:
logging.file=logs/facade_@env.identifier@.log问题是,当我启动我的应用程序时,即使指定了配置文件,我总是将其作为我的 env.identifier 开发人员的值。 如何解决这个问题?谢谢
【问题讨论】:
-
你不应该这样做。不要使用 Maven 配置文件来创建多个工件。这基本上意味着您将使用未经测试的工件进行生产。只需在针对不同环境启动应用程序时指定这些参数,而不是尝试为此使用 maven 配置文件。
标签: java spring maven spring-boot properties-file