Hello, trying to autowire JavaMailSender after adding:

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

to my POM.xml, like so:

@Autowired
private JavaMailSender sender;

but getting everytime: No qualifying bean of type org.springframework.mail.javamail.JavaMailSender found for dependency

My application contains also all properties needed (spring.mail.*) Is there i'am doing wrong? Greetings Alex

Comment From: wilkinsona

It works for me (I just tested with 1.2.3.RELEASE). Try looking at the MailSenderAutoConfiguration entry in the auto-configuration report to see why the bean hasn't been auto-configured. You can switch on the report by running with --debug, for example:

public static void main(String[] args) {
    SpringApplication.run(Gh2876Application.class, "--debug");
}

If that doesn't help, please provide a sample project that illustrates the problem.

Comment From: esodot

Dear Andy, thank you, it actually works for me now:

27.04.2015 15:07:35.898 DEBUG o.s.b.f.annotation.InjectionMetadata - Processing injected element of bean 'sample.traditional.LogtoolTests': AutowiredFieldElement for private org.springframework.mail.javamail.JavaMailSender sample.traditional.LogtoolTests.javaMailSender
27.04.2015 15:07:35.898 DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'mailSender'

my application-test.yml had a bug. Greetings Alex

Comment From: ghost

I am getting the same exception for my app while deploying it in PCF cloud. In local it is working fine. I have posted it on stack overflow but didn't get any answer. Your help would be appreciated. Thanks

Comment From: snicoll

@Arjun09 this issue is closed and Andy already answered that question (see https://github.com/spring-projects/spring-boot/issues/2876#issuecomment-96624625)

Comment From: zhugw

I have met the same problem when run app in tomcat

Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.springframework.mail.javamail.JavaMailSender' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}

but run Application directly do not have this problem.

Reason

when run app in tomcat do not load this configuration class

84 = {ConfigurationClass@4547} "ConfigurationClass: beanName 'org.springframework.boot.autoconfigure.mail.MailSenderAutoConfiguration', class path resource [org/springframework/boot/autoconfigure/mail/MailSenderAutoConfiguration.class]"

Solution Modify the Application class

@SpringBootApplication
public class SpringBootWebApplication extends SpringBootServletInitializer {

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(SpringBootWebApplication.class);
    }

    public static void main(String[] args) throws Exception {
        SpringApplication.run(SpringBootWebApplication.class, args);
    }

}

Please see : https://www.mkyong.com/spring-boot/spring-boot-deploy-war-file-to-tomcat/

Comment From: daschintu732

bakbas