[英]Share Spring Boot YAML configuration between two applications
I have two applications in the same maven project and have given each of them their own configuration file by setting the spring.config.name
property for each before invoking SpringApplication.run(). 我在同一个Maven项目中有两个应用程序,并且在调用SpringApplication.run()之前,通过为每个应用程序设置spring.config.name
属性,为它们提供了各自的配置文件。
This in the first application, I set spring.config.name
to server1
so it looks for server1
instead of application.yml
. 在第一个应用程序中,我将spring.config.name
设置为server1
因此它将查找server1
而不是application.yml
。 In the second I have set spring.config.name
to server2
. 在第二个中,我将spring.config.name
设置为server2
。
However I would like them to share the same logging configuration. 但是,我希望他们共享相同的日志记录配置。 Unfortunately, logging configuration cannot be imported via @PropertySource since logging is already configured before property-sources are read - see Logging section of Spring Boot manual. 不幸的是,无法通过@PropertySource导入日志记录配置,因为在读取属性源之前已经配置了日志记录 -请参见Spring Boot手册的“ 日志记录”部分 。
Is there any way I can do this? 有什么办法可以做到吗?
Spring Boot uses as default Logback. Spring Boot使用默认的Logback。 You can put a logback.xml file in src/main/resources to configure the log. 您可以将logback.xml文件放在src / main / resources中以配置日志。 And both applications will automatically use this file to configure their logging engine. 并且两个应用程序都将自动使用此文件来配置其日志记录引擎。
You can learn how to configure Logback here: http://logback.qos.ch/manual/configuration.html 您可以在此处了解如何配置Logback: http ://logback.qos.ch/manual/configuration.html
A simple example. 一个简单的例子。 It will set the log level to INFO and log to the Console: 它将日志级别设置为INFO并登录到控制台:
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<root level="info">
<appender-ref ref="STDOUT" />
</root>
</configuration>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.