-
Notifications
You must be signed in to change notification settings - Fork 12
Description
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:
- https://github.com/jdbc-observations/datasource-micrometer/blob/main/datasource-micrometer-spring-boot/src/main/java/net/ttddyy/observation/boot/autoconfigure/DataSourceObservationAutoConfiguration.java#L135
- https://github.com/gavlyukovskiy/spring-boot-data-source-decorator/blob/master/datasource-decorator-spring-boot-autoconfigure/src/main/java/com/github/gavlyukovskiy/boot/jdbc/decorator/DataSourceDecoratorAutoConfiguration.java#L60
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 ?