org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.springframework.mail.javamail.JavaMailSender] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@javax.inject.Inject(), @org.springframework.beans.factory.annotation.Qualifier(value=mailSender)}

Stack Overflow | Thịnh Kều | 2 months ago
tip
Do you find the tips below useful? Click on the to mark them and say thanks to rafael . Or join the community to write better ones.
  1. 0
    samebug tip
    You could be missing an annotation (@Service or @Component) or a definition in the xml. Also, look if the class where your implementation is located is properly scanned. (add this as source: https://goo.gl/PLJZGJ)
  2. 0
    samebug tip
    You could be missing na annotation (@Service or @Component) or the <bean> definition in the xml. Also, look if the class where your implementation is located is properly scanned (check "<context:component-scan base-package=")
    via goo.gl
  3. 0

    Could not autowire field: private org.springframework.mail.javamail.JavaMailSender com.badmap.controller.SignUpController.javaMailSender;

    Stack Overflow | 1 year ago | JonnyXia
    org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.mail.javamail.JavaMailSender com.badmap.controller.SignUpController.javaMailSender; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.springframework.mail.javamail.JavaMailSender] 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)}
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    Spring Boot multi module Maven project @Autowired does not work

    Stack Overflow | 2 years ago | ACV
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userServiceImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.mail.javamail.JavaMailSender service.impl.UserServiceImpl.mailSender; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.springframework.mail.javamail.JavaMailSender] 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)}
  6. 0

    I have a controller class with a field {{List<String>}} autowired: {code:java} @Autowired() @Qualifier("publicViews") private List<String> publicViews; {code} In my configuration I've wrote: {code:xml} <util:list id="publicViews" value-type="java.lang.String"> <value >gestione</value> <value >inserimento</value> <value >dettaglio</value> </util:list> <context:component-scan base-package="it.lispa.sire.tributi.aper_pdt.au.cicloquad.controllers" /> {code} When the application start spring throw an error: {noformat} org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [java.lang.String] found for dependency [collection of java.lang.String]: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true), @org.springframework.beans.factory.annotation.Qualifier(value=publicViews)} at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:997) at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:825) at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:779) at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:490) at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87) at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:287) .... {noformat} In the {{DefaultListableBeanFactory}} the search for autowire candidate get the collection type and use this type to search the candidate: {code:java} else if (Collection.class.isAssignableFrom(type) && type.isInterface()) { Class<?> elementType = descriptor.getCollectionType(); if (elementType == null) { if (descriptor.isRequired()) { throw new FatalBeanException("No element type declared for collection [" + type.getName() + "]"); } return null; } Map<String, Object> matchingBeans = findAutowireCandidates(beanName, elementType, descriptor); {code} I think that the system must search candidate for the {{type}} variable and not for {{elementType}}. In my issue the {{elementType}} is {{String}} not {{java.util.List}}.

    Spring JIRA | 3 years ago | Claudio D'Angelo
    org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [java.lang.String] found for dependency [collection of java.lang.String]: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true), @org.springframework.beans.factory.annotation.Qualifier(value=publicViews)}

  1. tzrlk 1 times, last 8 months ago
19 unregistered visitors
Not finding the right solution?
Take a tour to get the most out of Samebug.

Tired of useless tips?

Automated exception search integrated into your IDE

Root Cause Analysis

  1. org.springframework.beans.factory.NoSuchBeanDefinitionException

    No qualifying bean of type [org.springframework.mail.javamail.JavaMailSender] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@javax.inject.Inject(), @org.springframework.beans.factory.annotation.Qualifier(value=mailSender)}

    at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException()
  2. Spring Beans
    DefaultListableBeanFactory.preInstantiateSingletons
    1. org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:1100)
    2. org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:960)
    3. org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:855)
    4. org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:480)
    5. org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87)
    6. org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:289)
    7. org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1185)
    8. org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537)
    9. org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
    10. org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304)
    11. org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
    12. org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300)
    13. org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195)
    14. org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:700)
    14 frames
  3. Spring Context
    AbstractApplicationContext.refresh
    1. org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:760)
    2. org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482)
    2 frames
  4. Spring MVC
    HttpServletBean.init
    1. org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:643)
    2. org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:606)
    3. org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:657)
    4. org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:525)
    5. org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:466)
    6. org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136)
    6 frames
  5. JavaServlet
    GenericServlet.init
    1. javax.servlet.GenericServlet.init(GenericServlet.java:158)
    1 frame
  6. Glassfish Core
    ContainerBase$StartChild.call
    1. org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1241)
    2. org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1154)
    3. org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1041)
    4. org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4969)
    5. org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5255)
    6. org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    7. org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1408)
    8. org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1398)
    8 frames
  7. Java RT
    Thread.run
    1. java.util.concurrent.FutureTask.run(FutureTask.java:266)
    2. java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    3. java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    4. java.lang.Thread.run(Thread.java:745)
    4 frames