【问题标题】:Error while trying sending mail across gmail using logback and spring boot尝试使用 logback 和 spring boot 通过 gmail 发送邮件时出错
【发布时间】:2016-09-28 09:54:44
【问题描述】:

我正在使用弹簧靴:1.4.0。使用 logback 中的以下配置,我正在尝试向 gmail 发送邮件。

<appender name="EMAIL" class="ch.qos.logback.classic.net.SMTPAppender">
    <smtpHost>smtp.gmail.com</smtpHost>
    <smtpPort>25</smtpPort>
    <SSL>true</SSL>
    <username>*</username>
    <password>*</password>

    <to>*</to>
    <from>*</from>
    <subject>TESTING: %logger{20} - %m</subject>
    <layout class="ch.qos.logback.classic.PatternLayout">
        <pattern>%date %-5level %logger{35} - %message%n</pattern>
    </layout>
</appender>

<root level="DEBUG">
    <appender-ref ref="EMAIL" />
</root>

但是得到以下异常

Exception in thread "main" java.lang.IllegalStateException: Logback configuration error detected: 
ERROR in ch.qos.logback.core.joran.action.NestedBasicPropertyIA - Unexpected aggregationType AS_BASIC_PROPERTY_COLLECTION
at       org.springframework.boot.logging.logback.LogbackLoggingSystem.loadConfiguration(LogbackLoggingSystem.java:152)
at org.springframework.boot.logging.logback.LogbackLoggingSystem.reinitialize(LogbackLoggingSystem.java:195)
at org.springframework.boot.logging.AbstractLoggingSystem.initializeWithConventions(AbstractLoggingSystem.java:65)
at org.springframework.boot.logging.AbstractLoggingSystem.initialize(AbstractLoggingSystem.java:50)
at org.springframework.boot.logging.logback.LogbackLoggingSystem.initialize(LogbackLoggingSystem.java:106)
at org.springframework.boot.logging.LoggingApplicationListener.initializeSystem(LoggingApplicationListener.java:289)
at org.springframework.boot.logging.LoggingApplicationListener.initialize(LoggingApplicationListener.java:262)
at org.springframework.boot.logging.LoggingApplicationListener.onApplicationEnvironmentPreparedEvent(LoggingApplicationListener.java:231)
at org.springframework.boot.logging.LoggingApplicationListener.onApplicationEvent(LoggingApplicationListener.java:207)
at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:166)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:138)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:121)
at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:68)
at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:54)
at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:336)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:308)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1182)

主程序Spring Boot

public static void main(String[] args) {
    System.setProperty("log.name", "dynamicLogs");
    logger.debug("Start running debug");
    SpringApplication.run(WebApplication.class, args);
    logger.error("Start running error");            
}

如果我尝试运行一个测试 java 程序,它运行良好。不确定使用 spring boot 运行时出现什么问题。缺少要设置的任何属性?

【问题讨论】:

    标签: java spring email spring-boot logback


    【解决方案1】:

    logback 版本 1.1.7 存在一些问题。 Spring Boot 1.3.4 和 1.3.5 依赖于这个版本,所以 1.4.0 也可能。

    您可以尝试强制使用较旧/较新版本的 logback。

    更多信息在https://github.com/logstash/logstash-logback-encoder/issues/160

    【讨论】:

    • 尝试使用旧版本,没有帮助。我怀疑我缺少一些要在 logback 中配置的属性。
    • 您可以尝试删除一些属性。我遇到了 logback 不理解的属性的问题,删除该属性后它也可以工作。
    • 我认为这些是我用过的最低限度。
    【解决方案2】:

    您遇到了to 字段的问题。请参阅THIS 错误报告。您将不得不等待 1.1.8 或降级到版本 1.1.6。 使用 Spring Boot,您只需执行以下操作

    <properties>
        <logback.version>1.1.6</logback.version> 
    </properties>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-02-04
      • 2017-10-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-21
      • 2016-06-03
      • 1970-01-01
      相关资源
      最近更新 更多