gpt4 book ai didi

java - 如何打印 Spring Boot 加载的所有配置?

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:08:24 28 4
gpt4 key购买 nike

我想在屏幕上打印从配置文件加载的所有属性。我该怎么做?我找不到太多相关信息。

那是因为我可能会使用参数 --spring.config.location 加载配置文件,我想看看我是否正确加载了文件。

我正在寻找一个控制台解决方案,我可以在进程实际开始执行任务之前打印一些内容。

最佳答案

如果你使用 Spring Boot Actuator,你会得到一个 /env endpoint这会向您显示该信息。

要启用此功能,请将以下依赖项添加到您的项目中:

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

输出应该是这样的:

{
"profiles": [

],
"bootstrap": {

},
"commandLineArgs": {

},
"servletContextInitParams": {

},
"systemProperties": {
"jboss.i18n.generate-proxies": "true",
"java.runtime.name": "Java(TM) SE Runtime Environment",
"java.protocol.handler.pkgs": "null|org.springframework.boot.loader",
...
},
"systemEnvironment": {
"LOCALAPPDATA": "C:\\Windows\\system32\\config\\systemprofile\\AppData\\Local",
"PROCESSOR_LEVEL": "6",
"ProgramFiles": "C:\\Program Files",
"PUBLIC": "C:\\Users\\Public",
"NUMBER_OF_PROCESSORS": "2",
"windir": "C:\\Windows",
...
},
"applicationConfig: [file:.\/application.yml]": {
"server.port": 11016,
"server.tomcat.access-log-enabled": true,
"server.tomcat.access-log-pattern": "%h %l %u %t \"%r\" %>s %b %D",
"server.tomcat.basedir": ".\/",
...
},
"applicationConfig: [classpath:\/application.yml]": {
...
"spring.messages.basename": "messages",
"spring.messages.cache-seconds": -1,
"spring.messages.encoding": "UTF-8"
},
"defaultProperties": {
"spring.application.name": "bootstrap"
}
}

它显示了所有加载的配置文件,包括默认值、系统属性、通过配置服务加载的属性……。

关于java - 如何打印 Spring Boot 加载的所有配置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42412793/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com