Annotation-specified bean name conflicts with existing, non-compatible bean def

后端 未结 13 839
再見小時候
再見小時候 2021-01-31 01:51

I\'m having a problem with some Spring bean definitions. I have a couple of context xml files that are being loaded by my main() method, and both of them contain almost exclusiv

13条回答
  •  旧巷少年郎
    2021-01-31 01:52

    Scenario:

    I am working on a multi-module Gradle project.

    Modules are:

    - core, 
    - service,
    - geo,
    - report,
    - util and
    - some other modules.
    

    So primarily we have prepared a Component[locationRecommendHttpClientBuilder] in geo module.

    Java Code:

    import org.springframework.stereotype.Component
    
    @Component("locationRecommendHttpClientBuilder")
    class LocationRecommendHttpClientBuilder extends PanaromaHttpClientBuilder {
        @Override
        PanaromaHttpClient buildFromConfiguration() {
            this.setURL(PanaromaConf.getInstance().getString("locationrecommend.url"))
            this.setMethod(PanaromaConf.getInstance().getString("locationrecommend.method"))
            this.setProxyHost(PanaromaConf.getInstance().getString("locationrecommend.proxy.host"))
            this.setProxyPort(PanaromaConf.getInstance().getInt("locationrecommend.proxy.port", 0))
            return super.build()
        }
    }
    

    application-context.xml

    
    

    Then it is decided to add this component in core module.

    One engineer has previous code for geo module and then he has taken the latest module of core but he forgot to take the latest geo module.

    So the component[locationRecommendHttpClientBuilder] is double times in his project and he was getting the following error.

    Caused by: org.springframework.context.annotation.ConflictingBeanDefinitionException: Annotation-specified bean name 'LocationRecommendHttpClientBuilder' for bean class [au.co.google.app.locationrecommendation.builder.LocationRecommendHttpClientBuilder] conflicts with existing, non-compatible bean definition of same name and class [au.co.google.panaroma.platform.logic.impl.locationRecommendHttpClientBuilder]

    Solution Procedure:

    After removal the component from geo module, component[locationRecommendHttpClientBuilder] is only available in core module. So there is no conflicting situation. Issue is solved by this way.

提交回复
热议问题