Duplicate Spring Bean ID Problem investigation

Source: Internet
Author: User
Tags throw exception

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.