[Solved] Failed to instantiate [applets.nature.mapper.LogInfoMapper]: Specified class is an interface

I. Origin of the problem
When the project was tested on Sunday afternoon, something needed to be modified temporarily, and I had already typed a package to deploy to the test server for deployment. In the process of testing, I found a problem, that is
Now the code is running without problems, only that other people and things have not yet done, so temporarily modify the code logic, so that the test can proceed smoothly. themselves to modify the code immediately as needed.
And after deploying a version before, you have been modifying the new code yourself, some requirements are just set down. After the code was modified, the code was cleaned, compiled and packaged with idea without any problem.
However, an error was reported after startup as shown in the title. The detailed error message is as follows:

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2021-10-31 15:40:12.035 [] [main] ERROR o.s.boot.SpringApplication[826] - Application run failed
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'webLogAspect': Unsatisfied dependency expressed through field 'logInfoMapper'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'logInfoMapper' defined in file [D:\JavaWorkSpace\BigstuffParent\AppletsBackend\target\classes\applets\nature\mapper\LogInfoMapper.class]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [applets.nature.mapper.LogInfoMapper]: Specified class is an interface
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:643)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:130)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:399)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1422)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:594)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:323)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:321)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:879)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:878)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:550)
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:141)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:747)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:315)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215)
at applets.AppletsApplication.main(AppletsApplication.java:25)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'logInfoMapper' defined in file [D:\JavaWorkSpace\BigstuffParent\AppletsBackend\target\classes\applets\nature\mapper\LogInfoMapper.class]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [applets.nature.mapper.LogInfoMapper]: Specified class is an interface
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1320)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1214)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:557)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:323)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:321)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:276)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1287)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1207)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:640)
... 19 common frames omitted
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [applets.nature.mapper.LogInfoMapper]: Specified class is an interface
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:70)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1312)
... 30 common frames omitted
Disconnected from the target VM, address: '127.0.0.1:13616', transport: 'socket'

The key error message is Failed to instantiate [applets.nature.mapper.LogInfoMapper]: Specified class is an interface
Second, the problem analysis
themselves to this problem to the search engine inside a throw, immediately appear a large number of results. For example, the information provided by this blog post.
According to the problem encountered by the blogger in the article, there is a mapper.java interface file renamed, so when the start of the problem. This gave me an idea to solve the problem, could I also have the same problem?
With this question in mind, I immediately started looking for the cause of the problem.
III. Solution
After finding a direction to solve the problem, I immediately started to check whether the interface class applets.nature.mapper.LogInfoMapper has a duplicate name. In the project to repeatedly search, are not
I found only this one interface. Is the blogger’s answer incorrect? There is clearly only one interface in my project. This reason was temporarily ruled out by myself, so I continued to investigate the cause.
Checking way two:
Since this interface frequently reports errors when starting, I temporarily logged out this interface to try to see if it can start successfully. When I logged out the interface, I restarted it and found that it still reported errors, but no longer
LogInfoMapper class is not instantiated, but other classes cannot be instantiated. The error message is as follows:
Field userTaskMapper in applets.task.service.impl.UserTaskServiceImpl required a bean of type ‘applets.task.mapper.UserTaskMapper’ that could not be UserTaskMapper’ that could not be found.
The LogInfoMapper interface is the first to be called and is placed in the aop interceptor for logging. After logging it out, it reports that other interfaces are not instantiated properly.
Troubleshooting method three.
Since I got to this step, I simply backed up the code and rolled back all the modified code to the previous state, restarted the project and started successfully. Then I analyzed step by step whether I had added something or modified something
I added or modified the code. I found that when I added a new mapper.java interface and xml file, the project did not start properly, as shown below:

When I searched the project, I found two mapper interfaces with the same name

I immediately removed the newly added mapper interface, restarted the project, and the problem was solved.
From here I also learned that sometimes you can’t just look at the problem itself, you need to analyze the problem in depth. Just like this bug, the interface that reported the error is not duplicated.
Rather, the newly added interface is duplicated, resulting in all the mapper interfaces can not be properly instantiated, can not be instantiated can not be properly injected into the class, resulting in a series of subsequent problems.

Similar Posts: