[英]How to exclude default application.properties add custom properties file using profiles in maven for spring boot project?
I have developed a web application using spring boot. 我已经使用Spring Boot开发了一个Web应用程序。 I have three resource folders in src/main/resources staging,qa,production which consists of application properties and logging configuration for the specific environment.
我在src / main / resources阶段,qa,生产中有三个资源文件夹,其中包括针对特定环境的应用程序属性和日志记录配置。 Along with these folders I have application.properties and logging configuration in resources folder which I use it for dev environment.
除了这些文件夹外,我在资源文件夹中还有application.properties和日志记录配置,可将其用于开发环境。 I want to package war file according to the environment using spring-boot-maven plugin.
我想使用spring-boot-maven插件根据环境打包war文件。 I am new to maven any help would be appreciated?
我是新手,对您的帮助将不胜感激吗?
Convetion is application-{profileName}.properties
对流是
application-{profileName}.properties
Point 10 and 11: 点10和11:
http://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.html http://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.html
eg application-test.properties
it overrides the application.properties
Make profile in pom.xml
例如
application-test.properties
它覆盖了application.properties
在pom.xml
配置文件
Introduction to profiles: http://maven.apache.org/guides/introduction/introduction-to-profiles.html 个人资料简介: http : //maven.apache.org/guides/introduction/introduction-to-profiles.html
Rather than using Maven to add different folders to your classpath for each environment, you can use Spring profiles. 您可以使用Spring配置文件,而不是使用Maven为每个环境将不同的文件夹添加到类路径中。
First of all create different application.properties for each environment, such as: 首先为每个环境创建不同的application.properties ,例如:
For the logging you can use the logging.config
property. 对于日志记录,可以使用
logging.config
属性。 So, in application-staging.properties you could use: 因此,在application-staging.properties中,您可以使用:
logging.config=classpath:logback-staging.xml
In the other properties files you can use different logging.config
properties. 在其他属性文件中,可以使用其他
logging.config
属性。
Now just run your application with the spring.profiles.active
property. 现在,只需使用
spring.profiles.active
属性运行您的应用程序。
However, an easier solution would be to use externalized configuration . 但是,更简单的解决方案是使用外部化配置 。 Rather than having to rebuild each time you want to change configuration for a specific profile, you can externalize it by putting an application.properties file next to your JAR/WAR in the correct environment, rather than on your classpath.
您不必在每次更改特定概要文件的配置时都进行重建,而是可以通过在正确的环境中而不是在类路径上将application.properties文件放在JAR / WAR旁边来对其进行外部化。 Spring boot will pick this up automatically.
Spring Boot会自动将其启动。
Now you can also externalize your logging config by placing a logback.xml (or log4j2.xml, ...) file next to your JAR/WAR and just configure your (externalized) application properties with: 现在,您还可以通过在JAR / WAR旁边放置一个logback.xml(或log4j2.xml等)文件来外部化日志记录配置,并使用以下命令配置(外部化的)应用程序属性:
logging.config=file:logback.xml
This allows you to edit your configuration and logging without having to change your JAR/WAR. 这使您可以编辑配置和日志记录,而不必更改JAR / WAR。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.