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

EmailService not recognised in@Autowired #7

Closed
danysz opened this issue Jul 1, 2016 · 7 comments
Closed

EmailService not recognised in@Autowired #7

danysz opened this issue Jul 1, 2016 · 7 comments
Assignees
Labels

Comments

@danysz
Copy link

danysz commented Jul 1, 2016

Hi

I added

@ComponentScan(basePackages = {"my package name", "it.ozimov.springbooot.mail",
        "it.ozimov.springbooot.templating.mail.service"})

in the application class but when I still want to use the EmailService is not capable to Autowired it.

Here is the stack trace :

Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [it.ozimov.springboot.templating.mail.service.EmailService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}

Thanks for any advice..

Daniel

@robertotru
Copy link
Member

Hi Daniel,

Can you post the whole stacktrace? Moreover, which templating engine are you using (i.e. which of the provided modules)? Can you report the pom with the given dependencies?

@danysz
Copy link
Author

danysz commented Jul 1, 2016

I am not using any template ..
I tried to send a clean email first...

On Fri, Jul 1, 2016 at 9:08 PM, Roberto Trunfio notifications@github.com
wrote:

Hi Daniel,

Can you post the whole stacktrace? Moreover, which templating engine are
you using (i.e. which of the provided modules)? Can you report the pom with
the given dependencies?


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#7 (comment),
or mute the thread
https://github.com/notifications/unsubscribe/ABlzQKAw13KLH3naiKmFPuLzcHKgVoXgks5qRVeRgaJpZM4JDW29
.

Best regards

Daniel Szasz

@danysz
Copy link
Author

danysz commented Jul 1, 2016

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'restContUsers': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: public it.ozimov.springboot.templating.mail.service.EmailService com.retruster.server.api.restcontrollers.RestContUsers.emailService; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [it.ozimov.springboot.templating.mail.service.EmailService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334) ~[spring-beans-4.2.6.RELEASE.jar:4.2.6.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1214) ~[spring-beans-4.2.6.RELEASE.jar:4.2.6.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543) ~[spring-beans-4.2.6.RELEASE.jar:4.2.6.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) ~[spring-beans-4.2.6.RELEASE.jar:4.2.6.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.2.6.RELEASE.jar:4.2.6.RELEASE]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.2.6.RELEASE.jar:4.2.6.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.2.6.RELEASE.jar:4.2.6.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.2.6.RELEASE.jar:4.2.6.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:772) ~[spring-beans-4.2.6.RELEASE.jar:4.2.6.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:839) ~[spring-context-4.2.6.RELEASE.jar:4.2.6.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:538) ~[spring-context-4.2.6.RELEASE.jar:4.2.6.RELEASE]
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118) ~[spring-boot-1.3.5.RELEASE.jar:1.3.5.RELEASE]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:766) [spring-boot-1.3.5.RELEASE.jar:1.3.5.RELEASE]
    at org.springframework.boot.SpringApplication.createAndRefreshContext(SpringApplication.java:361) [spring-boot-1.3.5.RELEASE.jar:1.3.5.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:307) [spring-boot-1.3.5.RELEASE.jar:1.3.5.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1191) [spring-boot-1.3.5.RELEASE.jar:1.3.5.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1180) [spring-boot-1.3.5.RELEASE.jar:1.3.5.RELEASE]
    at com.retruster.server.api.RetrusterServerApiApplication.main(RetrusterServerApiApplication.java:15) [main/:na]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_91]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_91]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_91]
    at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_91]
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147) [idea_rt.jar:na]
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: public it.ozimov.springboot.templating.mail.service.EmailService com.retruster.server.api.restcontrollers.RestContUsers.emailService; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [it.ozimov.springboot.templating.mail.service.EmailService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:573) ~[spring-beans-4.2.6.RELEASE.jar:4.2.6.RELEASE]
    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88) ~[spring-beans-4.2.6.RELEASE.jar:4.2.6.RELEASE]
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331) ~[spring-beans-4.2.6.RELEASE.jar:4.2.6.RELEASE]
    ... 22 common frames omitted
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [it.ozimov.springboot.templating.mail.service.EmailService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:1373) ~[spring-beans-4.2.6.RELEASE.jar:4.2.6.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1119) ~[spring-beans-4.2.6.RELEASE.jar:4.2.6.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1014) ~[spring-beans-4.2.6.RELEASE.jar:4.2.6.RELEASE]
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:545) ~[spring-beans-4.2.6.RELEASE.jar:4.2.6.RELEASE]
    ... 24 common frames omitted

@robertotru
Copy link
Member

I don't see any particular issue. It should be something wrong your configuration.

I could try to help more, but you should post more code (e.g., the main application class). I also would like to see the pom dependencies (which version of the library are you using, essentially).

@danysz
Copy link
Author

danysz commented Jul 1, 2016

Hi

using the latest version : 0.3.2

springBootVersion = '1.3.5.RELEASE'

@SpringBootApplication
@ComponentScan(basePackages = {"com.retruster.server.api", "it.ozimov.springbooot.mail",
        "it.ozimov.springbooot.templating.mail.service"})
@EnableAsync
public class RetrusterServerApiApplication {


    public static void main(String[] args) {
        SpringApplication.run(RetrusterServerApiApplication.class, args);

    }

}

build.gradle

dependencies {
    compile('org.springframework.boot:spring-boot-starter-jdbc')
    compile('org.springframework.boot:spring-boot-starter-data-pa')

    compile('org.springframework.boot:spring-boot-starter-mail')
    compile('org.springframework.boot:spring-boot-starter-web'){
        exclude module: 'spring-boot-starter-tomcat'
    }
    compile('org.springframework.boot:spring-boot-starter-ws')
    runtime('org.postgresql:postgresql')
    compile("org.springframework.boot:spring-boot-starter-web:${springBootVersion}")
    compile("org.springframework.boot:spring-boot-starter-jetty:${springBootVersion}")

    compile('org.json:json:20160212')

    compile('it.ozimov:spring-boot-email-core:0.3.2')

    testCompile('org.springframework.boot:spring-boot-starter-test')


}

@robertotru
Copy link
Member

Hi Daniel,

There are two issues.
First, in your main set the following annotations:

@SpringBootApplication
@ComponentScan(basePackages = {"com.test", "it.ozimov.springboot"})
@EnableAsync

The readme wasn't updated after the last release, my bad.

Second, I have to make the TemplateService optional. So for now you need to also add a template-engine as dependency. I'll bugfix master this evening.

Thanks for reporting the issue

@robertotru
Copy link
Member

Release 0.3.3 is now on Maven Central.

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

No branches or pull requests

2 participants