【问题标题】:How to write properties in application.properties using Maven Archetype如何使用 Maven Archetype 在 application.properties 中编写属性
【发布时间】:2020-06-23 18:45:12
【问题描述】:

我正在创建一个原型,以便我的团队可以生成几个项目,但我遇到了问题。

我正在尝试将一个属性写入我的 application.properties 文件,但我似乎无法使其工作。我现在拥有的是这样的:

application.name=my-app-name <--- this should take the artifactId name
logging.file=logback-spring.xml

我尝试过使用 ${artifactId},但没有成功。有没有简单的方法可以做到这一点?

谢谢!

编辑:编辑只关注主要目标。

【问题讨论】:

  • 你在使用spring-boot-starter-parent吗?如果没有,您还有其他事情要做,此链接可能会有所帮助docs.spring.io/spring-boot/docs/current/reference/html/…
  • 我的 pom.xml 上有 spring-boot-starter-parent 。但是,这不是用于动态属性,比如我在@@ 之间的属性吗?我需要在项目生成时设置 spring.application.name,而不是在启动应用程序时设置。抱歉,如果我不明白您的意思,并感谢您的回复。 PD:编辑了主要问题,只关注 maven 原型而不是 Spring

标签: java maven properties maven-archetype


【解决方案1】:

如果 ${artifactId} 不起作用,可能是您的原型没有为资源激活过滤器,您可以将以下配置添加到您的 archetype-metadata.xml 中激活它

<archetype-descriptor>
  <fileSets>
    ...
    <fileSet filtered="true" packaged="false" encoding="UTF-8">
        <directory>src/main/resources/</directory>
    </fileSet>
    ...

【讨论】:

  • 做到了。谢谢!
猜你喜欢
  • 1970-01-01
  • 2016-08-10
  • 2017-08-27
  • 2013-11-30
  • 2014-09-02
  • 2017-06-17
  • 1970-01-01
  • 2018-12-16
  • 1970-01-01
相关资源
最近更新 更多