Tag Archives: Error creating bean with name

Spring Project Error: Error creating bean with name [How to Solve]

This kind of mistake is always encountered when doing exercises recently

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘com.example.Demo2MybatisApplicationTests’: Unsatisfied dependency expressed through field ‘userDao’; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type ‘com.example.dao.UserDao’ available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}

There is a long string of balabalabala at the beginning; There are many solutions on the Internet, and the problem I have is that I don’t add the annotation of package scanning

The @mapperscan (“interface path”) annotation is added to the spring startup class

Its function is to specify the package where the interface to become the implementation class is located, and then all interfaces under the package will generate corresponding implementation classes after compilation.

With this project, there will be no error that the bean is not found

Error creating bean with name [How to Solve]

I ran into a bug today

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'skuController'


The solution:

1. Maybe the implementation class didn’t add @servcie annotation. After you add it, click start, and the error still exists. Heartbreak X1 2. It may be that @mapperscan (“com. XXX. Mapper”) is not added to the startup class. After you add it, click start, and the error still exists. Heartbreak x2 3. Maybe the Dao package in serviceimpl is not imported into @ Autowired. After you add it, click start, and the error still exists. How about heartbreak X3
is it endless fun to be immortal and die? In the end, you have listed three possibilities, but you still need a note:
@ enable autoconfiguration

@The main functions of enable autoconfiguration are as follows:

Enable automatic configuration of the spring application context and try to guess and configure the beans you may need. Automatic configuration classes are usually based on class paths and defined bean applications. For example, if you have
tomcat-embedded.jar in your classpath, you may want a Tomcat embedded servletcontainerfactory (unless you define your own embedded servletcontainerfactory
bean). When using springbootapplication, automatic configuration of the context is automatically enabled and this annotation is added, so there is no extra effect
autoconfiguration tries to be as intelligent as possible and will be backed up when you define more of your own configurations. You can always manually exclude () any configuration you don’t want to apply (if you can’t access them). You can also exclude them through spring.
autoconfigure. Exclude attributes. After the user-defined bean is registered, auto configuration is always applied. Packages of classes annotated with @
enable autoconfiguration, usually through @
spring boot application, have special significance and are often used as “default”. For example, it will be used to scan the @ entity class. It is generally recommended to place @
enable autoconfiguration in the root package (if you do not use @ springbootapplication) so that you can search all subpackages and classes conditionalonclass and @ conditionalonsingbean).

The above explanations about @ enableautoconfiguration are copied from other places by bloggers. If it’s a bit difficult to understand, you just need to know that it’s Bean’s automatic assembly tool. Maybe you will ask, why do I do this?Can’t I use @ import directly in my project?Of course, since it is automatic configuration, of course, you want the project to start and load.

 

Error in project operation org.springframework.beans . factory.BeanCreationException : error creating bean with name can be configured by

I encountered this problem because the JDK memory and Tomcat I configured were not large enough, so the project ran with an error. I solved this problem through configuration.

JDK configuration memory size

-Xms500m -Xmx1024m -XX:NewSize=800m -XX:MaxPermSize=800m

Run eclipse normally, open window preferences Java, and the page window will pop up

 

 

Tomcat configuration is divided into two steps

The first step is to configure in eclipse

-Xms500m -Xmx1024m -XX:NewSize=256m -XX:MaxPermSize=512m

 

Find the path to configure and install tomcat, enter the bin file, and install Tomcat 7 by myself

-Xms500m
-Xmx1024m
-XX:PermSize=64M
-XX:MaxPermSize=256m
-XX:ReservedCodeCacheSize=48m
– Duser.timezone=GMT +08

 

After the configuration is completed, there is no error in running the project! Problem solving