首页 文章

从外部加载application.properties时,Spring Boot Logging级别无效

提问于
浏览
1

我正在用tomcat运行一个spring boot应用程序 .

通过类路径加载application.properties时,我的日志记录级别已正确设置 .

使用以下java配置从外部加载application.properties时:

@PropertySource(value="file:/some/path/application.properties")

“something”覆盖logging.level . *语句,似乎默认值设置为INFO级别 .

可能有什么不对?

1 回答

  • 5

    而不是使用 @PropertySource 并期望自定义Spring Boot加载规则仍然有效,让Spring Boot处理它 .

    Spring Boot已经支持loading profile specific property files . 通过default它检查类路径和当前目录 . 但是,通过指定 spring.config.location 属性可以轻松扩展/更改此属性 . 只需将您的自定义目录放在那里 .

    java -jar your-app.jar --spring.config.location=file:/some/path/
    

    Note: 将其设置为环境或JNDI也可以 .

    现在,还将根据相同的加载规则(即 application.propertiesapplication-{profile}.properties 以及当然的YAML文件)检查此目录的属性/ yml文件 .

相关问题