Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto-Configuration for Cassandra does not back off if a custom ReactiveSessionFactory is defined #21741

Closed
4 tasks done
tszmytka opened this issue Jun 7, 2020 · 6 comments
Closed
4 tasks done
Assignees
Labels
status: first-timers-only An issue that can only be worked on by brand new contributors status: superseded An issue that has been superseded by another type: bug A general bug

Comments

@tszmytka
Copy link
Contributor

tszmytka commented Jun 7, 2020

Hi, this is a first-timers-only issue. This means we've worked to make it more legible to folks who either haven't contributed to our codebase before, or even folks who haven't contributed to open source before.

If that's you, we're interested in helping you take the first step and can answer questions and help you out as you do. Note that we're especially interested in contributions from people from groups underrepresented in free and open source software!

If you have contributed before, consider leaving this one for someone new, and looking through our general ideal-for-contribution issues. Thanks!

Problem

The auto-configuration for Cassandra defines a ReactiveSessionFactory but does not check if the user has configured its own. The lack of check also means that the auto-configuration would potentially overrides the user's decision. Since Spring Boot works by default with bean overriding disabled, creating your own ReactiveSessionFactory leads to:

2020-06-07 15:26:34,604 DEBUG o.s.b.d.LoggingFailureAnalysisReporter [main] Application failed to start due to an exception
org.springframework.beans.factory.support.BeanDefinitionOverrideException: Invalid bean definition with name 'reactiveCassandraSessionFactory' defined in class path resource [org/springframework/boot/autoconfigure/data/cassandra/CassandraReactiveDataAutoConfiguration.class]: Cannot register bean definition [Root bean: class [null]; scope=; abstract=false; lazyInit=null; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.boot.autoconfigure.data.cassandra.CassandraReactiveDataAutoConfiguration; factoryMethodName=reactiveCassandraSessionFactory; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/boot/autoconfigure/data/cassandra/CassandraReactiveDataAutoConfiguration.class]] for bean 'reactiveCassandraSessionFactory': There is already [Root bean: class [null]; scope=; abstract=false; lazyInit=null; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=cassandraConfig; factoryMethodName=reactiveCassandraSessionFactory; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [dev/tomek/data-cassandra/sampleapplication/persistence/CassandraConfig.class]] bound.
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.registerBeanDefinition(DefaultListableBeanFactory.java:943) ~[spring-beans-5.2.6.RELEASE.jar:5.2.6.RELEASE]
	at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsForBeanMethod(ConfigurationClassBeanDefinitionReader.java:286) ~[spring-context-5.2.6.RELEASE.jar:5.2.6.RELEASE]
	at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsForConfigurationClass(ConfigurationClassBeanDefinitionReader.java:144) ~[spring-context-5.2.6.RELEASE.jar:5.2.6.RELEASE]
	at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitions(ConfigurationClassBeanDefinitionReader.java:120) ~[spring-context-5.2.6.RELEASE.jar:5.2.6.RELEASE]
	at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:331) ~[spring-context-5.2.6.RELEASE.jar:5.2.6.RELEASE]
	at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:236) ~[spring-context-5.2.6.RELEASE.jar:5.2.6.RELEASE]
	at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:280) ~[spring-context-5.2.6.RELEASE.jar:5.2.6.RELEASE]
	at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:96) ~[spring-context-5.2.6.RELEASE.jar:5.2.6.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:706) ~[spring-context-5.2.6.RELEASE.jar:5.2.6.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532) ~[spring-context-5.2.6.RELEASE.jar:5.2.6.RELEASE]
	at org.springframework.boot.web.reactive.context.ReactiveWebServerApplicationContext.refresh(ReactiveWebServerApplicationContext.java:62) ~[spring-boot-2.3.0.RELEASE.jar:2.3.0.RELEASE]
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:758) ~[spring-boot-2.3.0.RELEASE.jar:2.3.0.RELEASE]
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:750) [spring-boot-2.3.0.RELEASE.jar:2.3.0.RELEASE]
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) [spring-boot-2.3.0.RELEASE.jar:2.3.0.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) [spring-boot-2.3.0.RELEASE.jar:2.3.0.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1237) [spring-boot-2.3.0.RELEASE.jar:2.3.0.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) [spring-boot-2.3.0.RELEASE.jar:2.3.0.RELEASE]
	at dev.tomek.data-cassandra.sampleapplication.Sampleapplication.main(Sampleapplication.java:16) [main/:?]

Solution

The bean definition for reactiveCassandraSessionFactory should have a @ConditionalOnMissingBean so that it is not created if a bean of that type already exists.

Steps to Fix

  • Claim this issue with a comment below and ask any clarifying questions you need
  • Set up a repository locally following the Contributing Guidelines
  • Try to fix the issue following the steps above
  • Commit your changes and start a pull request.
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jun 7, 2020
@snicoll snicoll added status: first-timers-only An issue that can only be worked on by brand new contributors type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels Jun 8, 2020
@snicoll snicoll added this to the 2.3.x milestone Jun 8, 2020
@snicoll snicoll changed the title spring-boot and spring-data-cassandra create the same @Bean Auto-Configuration for Cassandra does not back off if a custom ReactiveSessionFactory is defined Jun 8, 2020
@flinden68
Copy link

I want to have a look at this issue. Good opportunity to set up everything as described in Contributing Guidelines

@tszmytka
Copy link
Contributor Author

tszmytka commented Jun 8, 2020

Hi @flinden68
Sorry but I already claimed this. I wrote this in the initial message but it got deleted while rephrasing by @snicoll
The issue was only to confirm my solution proposal.

@snicoll Could you please assign the issue to me? Or is such a note enough?

@flinden68
Copy link

@snicoll Is the solution by adding only @ConditionalOnMissingBean to the bean? Seems too easy

@flinden68
Copy link

@tszmytka No problem, just fix it. I will wait for another one

@snicoll
Copy link
Member

snicoll commented Jun 8, 2020

Fair enough @tszmytka. I've turn this as a first timer to let folks who never contributed to OSS to give it a go but you're right you've offered to help when you raised the issue. It's all yours.

@snicoll
Copy link
Member

snicoll commented Jun 10, 2020

Closing in favor of PR #21769

@snicoll snicoll closed this as completed Jun 10, 2020
@snicoll snicoll added the status: superseded An issue that has been superseded by another label Jun 10, 2020
@snicoll snicoll removed this from the 2.3.x milestone Jun 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: first-timers-only An issue that can only be worked on by brand new contributors status: superseded An issue that has been superseded by another type: bug A general bug
Projects
None yet
Development

No branches or pull requests

4 participants