【发布时间】:2018-03-20 20:05:39
【问题描述】:
我需要通过 maven 在我的 log4j2.xml 中添加一个环境变量,但是在 spring boot 项目中。我有一定的困难,但我做到了。 =)
以前的代码是怎样的。
log4j2.xml
<PatternLayout>
<Pattern>${ambiente} - %d [%-6p] %c - %M - %m%n</Pattern>
</PatternLayout>
pom.xml
<profiles>
<profile>
<id>dev</id>
<activation>
<property>
<name>env</name>
<value>dev</value>
</property>
</activation>
<properties>
<ambiente>desenvolvimento</ambiente>
</properties>
</profile>
<profile>
<id>hom</id>
<activation>
<property>
<name>env</name>
<value>hom</value>
</property>
</activation>
<properties>
<ambiente>homologacao</ambiente>
</properties>
</profile>
<profile>
<id>prod</id>
<activation>
<property>
<name>env</name>
<value>prod</value>
</property>
</activation>
<properties>
<ambiente>producao</ambiente>
</properties>
</profile>
</profiles>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
还有运行命令:clean install -Denv=dev
没用=(
<PatternLayout>
<Pattern>${ambiente} - %d [%-6p] %c - %M - %m%n</Pattern>
</PatternLayout>
【问题讨论】:
标签: maven spring-boot