spring - 我应该将Maven项目的应用程序配置文件放在哪里?

标签 spring maven-2

我正在使用Maven Application Assembler插件从Java项目生成独立的可执行文件。该应用程序读取配置文件,包括Spring文件。 Application Assembler插件具有一个选项(默认情况下处于激活状态),可以将etc/目录添加到应用程序的类路径中,但是我应该怎么做才能让该插件将配置文件复制到该目录中?

或更笼统地说,不应将不应打包在工件中的应用程序配置文件在Maven中的洁净位置放在哪里?

最佳答案

您还可以使用资源过滤:
http://maven.apache.org/guides/getting-started/index.html#How_do_I_filter_resource_files

打开过滤:

...
<build>
...
<resources>
      <resource>
        <directory>src/main/resources</directory>
        <filtering>true</filtering>
      </resource>
    </resources>
...
</build>
...

在src/main/resources下创建一个文件,例如:application.properties

application.properties
configprop.1=${param1}
configprop.2=${param2}

然后设置一个配置文件,并可能在settings.xml中设置一些属性
根据这是开发还是生产版本来设置不同的属性。
请参阅:http://maven.apache.org/guides/introduction/introduction-to-profiles.html

我有不同的属性集,具体取决于这是构建服务器,开发人员还是生产部署

mvn -Denv = dev || mvn -Denv = dev-build || mvn -Denv =生产

Maven链接有一个很好的描述。

关于spring - 我应该将Maven项目的应用程序配置文件放在哪里?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/465001/

相关文章:

java - 找不到 Spring Security : WebSecurityConfigurerAdapter. 类

java - Spring Security CSRF 训练模式

testing - 使用 Nexus 设置缺少 Maven 依赖项

java - 在 Eclipse 和 Maven 中使用 JUnit 的类路径问题

java - 如何发送 Maven 构建的电子邮件通知

spring jwt 解码器 openid token

java - Spring 5 Controller 返回html字符串以在浏览器中加载

spring - Servlet URL 模式匹配所有 URL

java - 马文 : Different property files for different profiles

maven-2 - 我应该使用 FTP 服务器作为 maven 主机吗?