BeanNotOfRequiredTypeException: Remember the tomcat service startup error caused by an improper dubbo reference

When deploying the service this afternoon, I found that the tomcat service could not be started. Exception: org.springframework.beans.factory.BeanCreationException:Error creating bean with name ‘manageFeeController’: Injection of resource dependencies failed. That is to say, the container failed to create the bean due to resource injection problems. Looking further back, this BeanCreation exception was caused by this error: org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named ‘platformAccountService’ must be of type [com.emaxcard.account.modules.account.service.PlatformAccountService] , but was actually of type [com.alibaba.dubbo.common.bytecode.proxy16] Translated as: The bean named ‘platformAccountService’ should be of type [com.emaxcard.account.modules.account.service.PlatformAccountService], but actually The above is the dubbo proxy class. Detailed stack information is as follows:

2021-11-25 14:49:21.411 [ERROR] [localhost-startStop-1] [org.springframework.web.context.ContextLoader:331] Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'manageFeeController': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named 'platformAccountService' must be of type [com.emaxcard.account.modules.account.service.PlatformAccountService], but was actually of type [com.alibaba.dubbo.common.bytecode.proxy16]
    at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:307)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1185)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:700)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:760)
--
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:1017)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:993)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:652)
    at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:1127)
    at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:2021)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)
Caused by: org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named 'platformAccountService' must be of type [com.emaxcard.account.modules.account.service.PlatformAccountService], but was actually of type [com.alibaba. dubbo.common.bytecode.proxy16]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:376)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200)
    at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.autowireResource(CommonAnnotationBeanPostProcessor.java:445)
    at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.getResource(CommonAnnotationBeanPostProcessor.java:419)
    at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor$ResourceElement.getResourceToInject(CommonAnnotationBeanPostProcessor.java:544)
    at org.springframework.beans.factory.annotation.InjectionMetadata$InjectedElement.inject(InjectionMetadata.java:155)
    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87)
    at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:304)
    ... 26 more

View Code

The platformAccountService in the current project is a dubbo service interface class. This bean is defined in the dubbo configuration file.

<dubbo:reference id="platformAccountService" interface="com.emaxcard.account.modules.service.PlatformAccountService"
timeout="5000"/>

Other dubbo services are also defined in this way. Why did this BeanNotOfRequiredTypeException suddenly appear when the service was restarted today?

It turns out that in the ManageFeeController mentioned in the error, the platformAccountService type introduced by import is com.emaxcard.account.modules.account.service.PlatformAccountService, and the type defined in dubbo configuration is com.emaxcard.account.modules.service.PlatformAccountService. If you look carefully, the two packages are different. The former package has an extra level of account. No wonder, since the bean is introduced as com..

import com.emaxcard.account.modules.account.service.PlatformAccountService;
import com.emaxcard.account.modules.account.vo.ManageFeeAccountVo;

@Controller
public class ManageFeeController {

    @Resource
    private PlatformAccountService platformAccountService;
    
    ...
}

Why is there no error when compiling the program?

It turns out that there are actually two PlatformAccountService interface classes in two different packages in the jar package of the rpc service that the current project depends on.

This situation is really misleading! So, how can the service provider define two PlatformAccountService interface classes at the same time? It turned out that when sorting out various API interfaces, the classmate put the PlatformAccountService under a new package, but did not delete the original package and the interface classes and dto classes in it. However, it caused trouble for the caller.