我将Logback添加到我的Spring Boot项目中,它在写入文件或标准输出时起作用。现在我想发送日志电子邮件,但如果我尝试配置SMTPAppender,我会收到以下错误:
记录系统无法使用配置进行初始化 '的logback-spring.xml' java.lang.IllegalStateException:Logback 检测到配置错误:ERROR in ch.qos.logback.core.joran.action.AppenderAction - 无法创建 类型为[ch.qos.logback.classic.net.SMTPAppender]的附加器。 ch.qos.logback.core.util.DynamicClassLoadingException:失败 实例化类型ch.qos.logback.classic.net.SMTPAppender错误 ch.qos.logback.core.joran.spi.Interpreter@8:76 - ActionException in 标签[appender]的操作 ch.qos.logback.core.joran.spi.ActionException: ch.qos.logback.core.util.DynamicClassLoadingException:失败 实例化类型ch.qos.logback.classic.net.SMTPAppender错误 ch.qos.logback.core.joran.action.AppenderRefAction - 找不到 appender命名为[EMAIL]。你有没有在下面而不是在上面定义它 配置文件?错误 ch.qos.logback.core.joran.action.AppenderRefAction - 请参阅 http://logback.qos.ch/codes.html#appender_order了解更多详情。在 org.springframework.boot.logging.logback.LogbackLoggingSystem.loadConfiguration(LogbackLoggingSystem.java:162) 在 org.springframework.boot.logging.AbstractLoggingSystem.initializeWithSpecificConfig(AbstractLoggingSystem.java:66) 在 org.springframework.boot.logging.AbstractLoggingSystem.initialize(AbstractLoggingSystem.java:56) 在 org.springframework.boot.logging.logback.LogbackLoggingSystem.initialize(LogbackLoggingSystem.java:115) 在 org.springframework.boot.logging.LoggingApplicationListener.initializeSystem(LoggingApplicationListener.java:308) 在 org.springframework.boot.logging.LoggingApplicationListener.initialize(LoggingApplicationListener.java:276) 在 org.springframework.boot.logging.LoggingApplicationListener.onApplicationEnvironmentPreparedEvent(LoggingApplicationListener.java:239) 在 org.springframework.boot.logging.LoggingApplicationListener.onApplicationEvent(LoggingApplicationListener.java:212) 在 org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:167) 在 org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139) 在 org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:122) 在 org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:73) 在 org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:54) 在 org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:336) 在 org.springframework.boot.SpringApplication.run(SpringApplication.java:307) 在 org.springframework.boot.SpringApplication.run(SpringApplication.java:1162) 在 org.springframework.boot.SpringApplication.run(SpringApplication.java:1151) 在 org.lh.cfpappserver.CfpAppServerApplication.main(CfpAppServerApplication.java:10) 线程" main"中的例外情况java.lang.IllegalStateException: java.lang.IllegalStateException:检测到Logback配置错误: ch.qos.logback.core.joran.action.AppenderAction中的错误 - 无法 创建一个类型为[ch.qos.logback.classic.net.SMTPAppender]的Appender。 ch.qos.logback.core.util.DynamicClassLoadingException:失败 实例化类型ch.qos.logback.classic.net.SMTPAppender错误 ch.qos.logback.core.joran.spi.Interpreter@8:76 - ActionException in 标签[appender]的操作 ch.qos.logback.core.joran.spi.ActionException: ch.qos.logback.core.util.DynamicClassLoadingException:失败 实例化类型ch.qos.logback.classic.net.SMTPAppender错误 ch.qos.logback.core.joran.action.AppenderRefAction - 找不到 appender命名为[EMAIL]。你有没有在下面而不是在上面定义它 配置文件?错误 ch.qos.logback.core.joran.action.AppenderRefAction - 请参阅 http://logback.qos.ch/codes.html#appender_order了解更多详情。在 org.springframework.boot.logging.LoggingApplicationListener.initializeSystem(LoggingApplicationListener.java:315) 在 org.springframework.boot.logging.LoggingApplicationListener.initialize(LoggingApplicationListener.java:276) 在 org.springframework.boot.logging.LoggingApplicationListener.onApplicationEnvironmentPreparedEvent(LoggingApplicationListener.java:239) 在 org.springframework.boot.logging.LoggingApplicationListener.onApplicationEvent(LoggingApplicationListener.java:212) 在 org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:167) 在 org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139) 在 org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:122) 在 org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:73) 在 org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:54) 在 org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:336) 在 org.springframework.boot.SpringApplication.run(SpringApplication.java:307) 在 org.springframework.boot.SpringApplication.run(SpringApplication.java:1162) 在 org.springframework.boot.SpringApplication.run(SpringApplication.java:1151) 在 org.lh.cfpappserver.CfpAppServerApplication.main(CfpAppServerApplication.java:10) 引起:java.lang.IllegalStateException:Logback配置 检测到错误:ERROR in ch.qos.logback.core.joran.action.AppenderAction - 无法创建 类型为[ch.qos.logback.classic.net.SMTPAppender]的附加器。 ch.qos.logback.core.util.DynamicClassLoadingException:失败 实例化类型ch.qos.logback.classic.net.SMTPAppender错误 ch.qos.logback.core.joran.spi.Interpreter@8:76 - ActionException in 标签[appender]的操作 ch.qos.logback.core.joran.spi.ActionException: ch.qos.logback.core.util.DynamicClassLoadingException:失败 实例化类型ch.qos.logback.classic.net.SMTPAppender错误 ch.qos.logback.core.joran.action.AppenderRefAction - 找不到 appender命名为[EMAIL]。你有没有在下面而不是在上面定义它 配置文件?错误 ch.qos.logback.core.joran.action.AppenderRefAction - 请参阅 http://logback.qos.ch/codes.html#appender_order了解更多详情。在 org.springframework.boot.logging.logback.LogbackLoggingSystem.loadConfiguration(LogbackLoggingSystem.java:162) 在 org.springframework.boot.logging.AbstractLoggingSystem.initializeWithSpecificConfig(AbstractLoggingSystem.java:66) 在 org.springframework.boot.logging.AbstractLoggingSystem.initialize(AbstractLoggingSystem.java:56) 在 org.springframework.boot.logging.logback.LogbackLoggingSystem.initialize(LogbackLoggingSystem.java:115) 在 org.springframework.boot.logging.LoggingApplicationListener.initializeSystem(LoggingApplicationListener.java:308) ......还有13个
这是我在logback-spring.xml文件中的配置:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<include resource="org/springframework/boot/logging/logback/defaults.xml"/>
<property name="LOG_FILE" value="${LOG_FILE:-${LOG_PATH:-${LOG_TEMP:-${java.io.tmpdir:-/tmp}}/}spring.log}"/>
<include resource="org/springframework/boot/logging/logback/file-appender.xml"/>
<appender name="EMAIL" class="ch.qos.logback.classic.net.SMTPAppender">
<asynchronousSending>false</asynchronousSending>
<smtpHost>smtp.gmail.com</smtpHost>
<to>my email</to>
<from>my email</from>
<username>xxx</username>
<password>xxx</password>
<subject>%logger{20} - %m</subject>
<layout class="ch.qos.logback.classic.html.HTMLLayout"/>
<cyclicBufferTracker class="ch.qos.logback.core.spi.CyclicBufferTracker">
<bufferSize>1</bufferSize>
</cyclicBufferTracker>
<starttls>true</starttls>
</appender>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<filter class="org.lh.cfpappserver.util.StdOutFilter"/>
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<root level="INFO">
<appender-ref ref="FILE"/>
<appender-ref ref="EMAIL"/>
<appender-ref ref="STDOUT"/>
</root>
</configuration>
我的配置错误导致应用程序无法启动?