Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autowire JavaMailSender with spring-boot-starter-mail not working? #2876

Closed
esodot opened this issue Apr 24, 2015 · 6 comments
Closed

Autowire JavaMailSender with spring-boot-starter-mail not working? #2876

esodot opened this issue Apr 24, 2015 · 6 comments

Comments

@esodot
Copy link

esodot commented Apr 24, 2015

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

@wilkinsona
Copy link
Member

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.

@wilkinsona wilkinsona added the status: waiting-for-feedback We need additional information before we can continue label Apr 27, 2015
@esodot
Copy link
Author

esodot commented Apr 27, 2015

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

@esodot esodot closed this as completed Apr 27, 2015
@dsyer dsyer removed the status: waiting-for-feedback We need additional information before we can continue label Apr 27, 2015
@ghost
Copy link

ghost commented Feb 7, 2017

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

@snicoll
Copy link
Member

snicoll commented Feb 8, 2017

@arjun09 this issue is closed and Andy already answered that question (see #2876 (comment))

@zhugw
Copy link

zhugw commented Mar 15, 2018

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/

@daschintu732

This comment was marked as spam.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants