【问题标题】:"Application failed to start" after spring-boot-starter-mail usagespring-boot-starter-mail 使用后“应用程序无法启动”
【发布时间】:2020-02-19 02:49:30
【问题描述】:

想基于spring-boot-starter-mail实现简单的邮件发件人解决方案 添加依赖项并设置属性后,我尝试运行应用程序并发生错误。 我认为值得注意的是,我不是,也不是要实现 Spring Cloud。只是邮件服务。 不明白为什么 spring boot 需要来自这些包的一些服务。

尝试了各种版本的依赖,定义了一些 @Beans 但不认为这是问题

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-mail</artifactId>
            <version>2.0.1.RELEASE</version>
        </dependency>

日志:

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2019-10-23 00:07:05.752 ERROR 19576 --- [  restartedMain] o.s.b.d.LoggingFailureAnalysisReporter   : 

***************************
APPLICATION FAILED TO START
***************************

Description:

Parameter 1 of method mailNotifier in de.codecentric.boot.admin.server.config.AdminServerNotifierAutoConfiguration$MailNotifierConfiguration required a bean of type 'de.codecentric.boot.admin.server.domain.entities.InstanceRepository' that could not be found.

The following candidates were found but could not be injected:
    - Bean method 'instanceRepository' in 'AdminServerAutoConfiguration' not loaded because @ConditionalOnBean (types: de.codecentric.boot.admin.server.config.AdminServerMarkerConfiguration$Marker; SearchStrategy: all) did not find any beans of type de.codecentric.boot.admin.server.config.AdminServerMarkerConfiguration$Marker


Action:

Consider revisiting the entries above or defining a bean of type 'de.codecentric.boot.admin.server.domain.entities.InstanceRepository' in your configuration.

只想通过 smtp.gmail.com 发送电子邮件 希望spring-boot-starter-mail 就足够了。

谢谢!

【问题讨论】:

  • 您似乎正在使用其他依赖项,例如导致错误的 Spring Boot Admin。如果您只想发送邮件,我认为将spring-boot-starter-parentspring-boot-starterspring-boot-starter-mail 添加到您的POM 文件中就足够了。

标签: java spring spring-boot email smtp


【解决方案1】:

正如 LHCHIN 所说,这是&lt;dependencyManagement/&gt; 中的spring-boot-admin-starter-serverspring-boot-admin-dependencies 的问题

【讨论】:

    【解决方案2】:

    我总是建议避免使用它们的版本复制粘贴依赖项。大多数情况下你不需要指定版本,让Spring boot根据mvn来判断哪个版本适合你。

    对于spring boot starter mail,我只需要以下依赖项

    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-context-support</artifactId>
      <version>5.2.8.RELEASE</version>
    </dependency>
    
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-mail</artifactId>
      <version>2.5.6</version>
    </dependency>
    

    我使用的来源是:https://www.baeldung.com/spring-email,无论有没有版本,它都对我有用。

    【讨论】:

      猜你喜欢
      • 2020-07-27
      • 2020-11-06
      • 2015-05-10
      • 2020-08-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多