@Autowired - No qualifying bean of type found for dependency

前端 未结 17 1551
自闭症患者
自闭症患者 2020-12-07 15:00

I\'ve started my project by creating entities, services and JUnit tests for services using Spring and Hibernate. All of this works great. Then I\'ve added spring-mvc to make

相关标签:
17条回答
  • 2020-12-07 15:37

    Spent much of my time with this! My bad! Later found that the class on which I declared the annotation Service or Component was of type abstract. Had enabled debug logs on Springframework but no hint was received. Please check if the class if of abstract type. If then, the basic rule applied, can't instantiate an abstract class.

    0 讨论(0)
  • 2020-12-07 15:38

    This may help you:

    I have the same exception in my project. After searching while I found that I am missing the @Service annotation to the class where I am implementing the interface which I want to @Autowired.

    In your code you can add the @Service annotation to MailManager class.

    @Transactional
    @Service
    public class MailManager extends AbstractManager implements IMailManager {
    
    0 讨论(0)
  • 2020-12-07 15:39

    I ran in to this recently, and as it turned out, I've imported the wrong annotation in my service class. Netbeans has an option to hide import statements, that's why I did not see it for some time.

    I've used @org.jvnet.hk2.annotations.Service instead of @org.springframework.stereotype.Service.

    0 讨论(0)
  • 2020-12-07 15:40
    • One reason BeanB may not exist in the context
    • Another cause for the exception is the existence of two bean
    • Or definitions in the context bean that isn’t defined is requested by name from the Spring context

    see more this url:

    http://www.baeldung.com/spring-nosuchbeandefinitionexception

    0 讨论(0)
  • 2020-12-07 15:42

    If you are testing your controller. Don't forget to use @WebAppConfiguration on your test class.

    0 讨论(0)
提交回复
热议问题