我想在屏幕上打印从配置文件加载的所有属性.我该怎么做?我找不到太多关于此的信息.
那是因为我可以使用参数--spring.config.location加载配置文件, 我想看看我是否正确加载了文件.
我正在寻找一个控制台解决方案,我可以在流程实际开始执行任务之前打印.
如果您使用Spring Boot Actuator,您将获得一个向您显示该信息的/env端点.
要启用此功能,请将以下依赖项添加到项目中:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
Run Code Online (Sandbox Code Playgroud)
输出应如下所示:
{
"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"
}
}
Run Code Online (Sandbox Code Playgroud)
它显示所有已加载的配置文件,包括默认值,系统属性,通过配置服务加载的属性,....
| 归档时间: |
|
| 查看次数: |
3295 次 |
| 最近记录: |