springboot error solution org.springframework.beans.factory.BeanCreationException: Error creating bean with nam

Create a new springboot project, and the backend uses the mybatisplus code generator.

There is no problem when using the test class to test the mapper layer, but the test service always reports an error, and the content of the error is as follows.

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.lantu.xadmin.XAdminApplicationTests': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.lantu.sys.mapper.UserMapper' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@javax.annotation.Resource(shareable=true, lookup=, name=, description=, authenticationType=CONTAINER, type=class java.lang.Object, mappedName=)}

Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.lantu.sys.mapper.UserMapper' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@javax.annotation.Resource(shareable=true, lookup=, name=, description=, authenticationType=CONTAINER, type=class java.lang.Object, mappedName=)}

I checked online and also asked chathpt. It is said that the annotations were not added, but I obviously added them.

This is my implementation class annotation

 Start class annotation

Test class annotation

 In the end, it was found that it was a file directory problem.

The startup class must be in the same directory as sys. Before, a package at the same level as sys was built, and the startup class was placed under that package.

The problem is solved and the startup is successful.

Guess you like

Origin blog.csdn.net/lina_lee1/article/details/130316101
Recommended