2017-04-03 84 views
-1

这是我的属性文件,在那里我有加入此变量我的属性 databaseEnabled = $ {} db.activedb如何更新属性文件中使用的pom.xml通过命令行

路径文件 的src /主/资源/ application-dev.properties

这是我pom.xml,我已经加入此代码

<build> 
    <finalName>spring-boot</finalName> 
    <plugins> 
     <plugin> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-maven-plugin</artifactId> 
     </plugin> 
    </plugins> 
    <resources> 
     <resource> 
      <directory>src/main/resources</directory> 
      <filtering>true</filtering> 
     </resource> 
     <resource> 
      <directory>src/test/resources</directory> 
      <filtering>true</filtering> 
     </resource> 
    </resources> 
</build> 

<profiles> 
    <profile> 
     <id>dynamo</id> 
     <activation> 
      <property> 
       <name>env</name> 
       <value>dynamo</value> 
      </property> 
     </activation> 
     <properties> 
      <db.activedb>dynamodb</db.activedb> 
     </properties> 
    </profile> 
    <profile> 
     <id>mongo</id> 
     <activation> 
      <property> 
       <name>env</name> 
       <value>mongo</value> 
      </property> 
     </activation> 
     <properties> 
      <db.activedb>mongodb</db.activedb> 
     </properties> 
    </profile> 
</profiles> 
+2

和你的问题是什么?阅读[问]并改善您的问题 – Jens

回答

0

添加includes标签:

<resource> 
    <directory>src/main/resources</directory> 
     <filtering>true</filtering> 
     <includes> 
      <include>/application-dev.properties</include> 
     </includes> 
    </resource> 
</resource> 

要使用-P选项设置简介:

mvn package -P mongo

检查结果开target/classes/application.properties文件。

+0

这没关系,但是当我尝试访问我的代码像@Value(“$ {databaseEnabled}”) 私人字符串databaseEnabled;我得到注入自动装配依赖失败;嵌套异常是java.lang.IllegalArgumentException:无法解析字符串值“$ {db.activedb}”中的占位符'db.activedb'“ –