problem Background : Testing from the local call server's Dubbo interface
Realization Idea : Opportunity Idea+spring+maven+dubbo Build test project, call from local directly
Specific implementation ideas can refer to the blog: https://www.cnblogs.com/xiuxingzhe/p/9250737.html
encounter problem : After the test target jar is introduced, the error is as follows when calling its interface to run the test class
caused by:java.lang.IllegalStateException:Duplicate spring Bean ID Cfgdistributorserviceimpl at Com.alibaba.dubbo . Config.spring.schema.DubboBeanDefinitionParser.parse (Dubbobeandefinitionparser.java:106) at Com.alibaba.dubbo.config.spring.schema.DubboBeanDefinitionParser.parse (Dubbobeandefinitionparser.java: 77) at Org.springframework.beans.factory.xml.NamespaceHandlerSupport.parse (Namespacehandlersupport.java:74) at Org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement ( Beandefinitionparserdelegate.java:1411) at Org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement ( Beandefinitionparserdelegate.java:1401) at Org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseBeanDefinitions ( Defaultbeandefinitiondocumentreader.java:168) at Org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.doRegisterBeanDefinitions ( Defaultbeandefinitiondocumentreader.java:138) at Org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.registerBeanDefinitions ( Defaultbeandefinitiondocumentreader.java:94) at Org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions ( Xmlbeandefinitionreader.java:508) at Org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions ( Xmlbeandefinitionreader.java:392)
Survey Ideas :
1. Check if spring in the project has two identical profiles loaded
Spring for duplicate ID, the default processing policy is to overwrite
However, Dubbo's new version of the duplicate ID has been given special treatment, if there are repeated direct throw exception, the above problem will occur
Check results: The configuration file is not loaded repeatedly in your own project
2.spring Scan Project will not only scan the current project Dubbo consumers, new classes, etc. need to register the bean
Classes in the jar package introduced in Pom.xml are also scanned with the following annotations: @Component, @Repository, @Service, @Controller, @RestController, @ControllerAdvice, @ Configuration
Therefore, in the introduction of the package, the service package cannot be introduced, because the service layer class contains more annotations @service, need to introduce the facade interface layer of the jar package
Check, you introduced the service layer of the jar package, this problem found
<dependency> <groupId>com.msa.base</groupId> <artifactid>base-service</ artifactid> <version>1.0-SNAPSHOT</version> </dependency>
Modification to the introduction of the facade layer
<dependency> <groupId>com.msa.base</groupId> <artifactid>base-service-facade </artifactId> <version>1.0-SNAPSHOT</version> </dependency>
Re-run test class: Call succeeded
Duplicate Spring Bean ID Problem investigation