Home > Java > javaTutorial > body text

No qualifying bean of typefound for: error occurs

巴扎黑
Release: 2017-06-26 11:30:45
Original
7283 people have browsed it

1. Problem: An error occurs when starting Tomcat!
The main error codes are as follows

No qualifying bean of type [com.*.*.*.*.*.dao.InfoDao] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@javax.annotation.Resource(shareable=true, mappedName=, description=, name=, type=class java.lang.Object, authenticationType=CONTAINER)}
Copy after login
  • 1

  • ##1

There is an error code before this code:

WARN  o.s.w.c.s.XmlWebApplicationContext - Exception encountered during context initialization - cancelling refresh attempt
Copy after login

  • 1

    ##1
  • 2. The environment where the error occurred: under the spring MVC + MyBatis framework, it involves the control layer, service layer, and dao layer.
3. Problem analysis: At first, I thought it was an exception caused by the use of @Resource in the control layer. However, after layer-by-layer investigation, the root cause of the error was caused by the annotations in the service layer. I found relevant information on the Internet and said: Dao class not found

Note: There is no problem with my annotation path, but an error still occurs.
4. The reason for my error: I created a multi-level directory in the project directory, and

<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
Copy after login

    1
  • to the applicationContext.xml file
    1
  • There is no "add" multi-level configuration in the tag (the original configuration file only has two levels of directories, and another level needs to be added) )
5. Solution to the problem: There is an applicationContext.xml file in the project. After opening it, it will look like the figure below:



Note: (1) Find the bean label. The initial setting is only the first one. Two, and my solution is to add the content in the blue box at the end to solve the above problem. No qualifying bean of typefound for: error occurs (2) As mentioned in the "Note" in point 3 above: My error was not caused by the annotation path, but because the automatic scanning directory set in the configuration file was level 2, and I wanted The running code is a level 3 directory, so an additional level is required.
(3) Based on most of the causes of this error on the Internet, I think it is mainly to make modifications in the configuration file (mine is applicationContext.xml), pay special attention to

This basically occurs The errors are all xml file mapping path errors, check whether the path is correct

This article is not original and was obtained from Baidu when encountering problems. It was indeed found that the mapping path is wrong. I also tested other paths and this error was always reported

The above is the detailed content of No qualifying bean of typefound for: error occurs. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template