Skip to content

there is a collision in dataSourceNameResolver bean name when both datasource-micrometer-spring-boot and p6spy-spring-boot-starter are used together #68

@lrozek

Description

@lrozek

Both datasource-micrometer-spring-boot and p6spy-spring-boot-starter create bean with the same name, ie dataSourceNameResolver leading to following exception:

org.springframework.beans.factory.support.BeanDefinitionOverrideException: Invalid bean definition with name 'dataSourceNameResolver' defined in class path resource [net/ttddyy/observation/boot/autoconfigure/DataSourceObservationAutoConfiguration.class]: Cannot register bean definition [Root bean: class=null; scope=; abstract=false; lazyInit=null; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; fallback=false; factoryBeanName=net.ttddyy.observation.boot.autoconfigure.DataSourceObservationAutoConfiguration; factoryMethodName=dataSourceNameResolver; initMethodNames=null; destroyMethodNames=[(inferred)]; defined in class path resource [net/ttddyy/observation/boot/autoconfigure/DataSourceObservationAutoConfiguration.class]] for bean 'dataSourceNameResolver' since there is already [Root bean: class=null; scope=; abstract=false; lazyInit=null; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; fallback=false; factoryBeanName=com.github.gavlyukovskiy.boot.jdbc.decorator.DataSourceDecoratorAutoConfiguration; factoryMethodName=dataSourceNameResolver; initMethodNames=null; destroyMethodNames=[(inferred)]; defined in class path resource [com/github/gavlyukovskiy/boot/jdbc/decorator/DataSourceDecoratorAutoConfiguration.class]] bound.

Here are the references for the collision:

Thanks to the presence of @ConditionalOnMissingBean I could easily workaround it by providing DataSourceNameResolver bean under different name like this:

@Configuration
class DefaultDataSourceNameResolverConfiguration {

    @Bean
    fun observationDataSourceNameResolver() = DefaultDataSourceNameResolver()

}

Would it be possible to create DefaultDataSourceNameResolver under different name to avoid this collision and both libs could be used together without issue ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions