ozimov / spring-boot-email-tools

A set of services and tools for sending emails in a Spring Boot 1.5.x application using a Template Engine

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

BeanCreationException - When using basic email.

redrails opened this issue · comments

Very similar to this issue: #7 and this one: #48.

The only difference being that I am using @EnableEmailTools:

@SpringBootApplication
@EnableEmailTools
public class AdeyTrackApplication implements ApplicationRunner {	
    public static void main(String[] args) {
        SpringApplication.run(AdeyTrackApplication.class, args);
    }
}

I want to send an email when someone goes to "/Search/EmailTest" so I do:

	@Autowired
	private EmailService emailService;
	
	@RequestMapping(value="/Search/EmailTest", method = RequestMethod.GET)
	public ModelAndView TestEmail() throws UnsupportedEncodingException {
		
		final Email email = DefaultEmail.builder()
		        .from(new InternetAddress("jon@domain.com", "jon doe"))
		        .to(Lists.newArrayList(new InternetAddress("jane@domain.com", "jane doe")))
		        .subject("Track email test")
		        .body("testing email")
		        .encoding("UTF-8").build();

		   emailService.send(email);
		
		return new ModelAndView("index");
	}

I can't seem to get here because the application doesn't even start up and I get the following exceptions: BeanCreationException and UnsatisfiedDependencyException.

Here is part of my build.gradle file:

dependencies {
    compile("org.springframework.boot:spring-boot-starter-web")
    testCompile("org.springframework.boot:spring-boot-starter-test")
    compile("org.springframework.boot:spring-boot-starter-data-rest")
    compile('org.springframework.boot:spring-boot-starter-mail')
    

   compile("org.springframework.boot:spring-boot-starter-actuator")

    // JPA
    compile("org.springframework.boot:spring-boot-starter-data-jpa")
    runtime("mysql:mysql-connector-java")
    compile("org.hibernate:hibernate-validator")
    compile("com.h2database:h2")

    // JSP
    compile("org.apache.tomcat.embed:tomcat-embed-jasper:8.0.23")
    compile("javax.servlet:jstl:1.2")

    // Security
    compile("org.springframework.boot:spring-boot-starter-security")
    testCompile("org.springframework.security:spring-security-test:4.0.1.RELEASE")

    // junit
    testCompile("org.springframework.security:spring-security-test:4.0.1.RELEASE")
    compile 'org.springframework.security:spring-security-taglibs:4.0.1.RELEASE'
    testCompile("junit:junit:4.12")

    compile("org.webjars:handsontable:0.17.0")
    compile("org.webjars:jquery:2.0.3-1")
    compile("org.webjars:bootstrap:3.3.5")
    compile("com.google.code.gson:gson:1.7.2")
    
    
    compile("it.ozimov:spring-boot-email-core:0.6.2")
    
    compile group: 'javax.mail', name: 'mail', version: '1.4'
}

When I run the application, I get the following exception https://gist.github.com/redrails/8ef251d15d22ce560a22663375afa684
(Posted on gist as it's gigantic)

TL;DR exception:
No qualifying bean of type [it.ozimov.springboot.mail.service.TemplateService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency.

I cannot seem to get to the root of this problem.

Also worth mentioning that I saw this issue too: #9
And tried following the example using @Service instead of directly Autowiring EmailService but I'm still getting the same it.ozimov.springboot.mail.service.TemplateService exception.

You are using SpringBoot 1.3.0.M2.
This is not supported by the extension. Upgrade to version 1.5.2.RELEASE

@robertotru Seems to be working great now, thanks for the help. I didn't see that this minimum requirement/dependency was stated anywhere so I assumed it's supported with my version.

Correct, I probably should highlight this. Thanks for reporting.