logback.xml springproperty:如何解密密码

时间:2016-05-11 01:20:56

标签: spring-boot logback jasypt

我们正在使用spring-boot和logback并存储数据库用户名& spring application.yaml中的加密密码。我们如何在logback.xml中获取解密的密码,以便dbAppender可以连接到数据库?

感谢您的帮助。

application.yaml

datasource:
        username: root
        password: ENC(xxxxxxxxxxxxxxxxx)

logback.xml

    <springProperty scope="context" name="db.user" source="datasource.username"/>
    <springProperty scope="context" name="db.password" source="datasource.password"/>
    <appender name="DB" class="ch.qos.logback.classic.db.DBAppender">
    <connectionSource class="ch.qos.logback.core.db.DriverManagerConnectionSource">
      <driverClass>com.mysql.jdbc.Driver</driverClass>
      <url>jdbc:mysql://host_name:3306/datebase_name</url>
      <username>${db.user}</username>
      <password>${db.password}</password>
    </connectionSource>
  </appender>

1 个答案:

答案 0 :(得分:0)

对于加密属性,请使用Encryption and Decryption

有关在回溯中使用属性的信息,请参阅Logback extensions

但是,您无法在logback-spring.xml中实际使用它。因为它过早地初始化并且加密的属性没有准备好。请参阅issue