-
Notifications
You must be signed in to change notification settings - Fork 635
spring-rabbit-test: rabbitListenerAnnotationProcessor has already been defined #914
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
Comments
Just looked into how RabbitBootstrapConfiguration gets loaded in my tests. Using Now, I can't do And even if I could, there are probably some parts of Things to try:
Related spring topic: spring-projects/spring-boot#15216 |
I am not sure why you opened an issue here; this has nothing to do with this project. Can you explain what you think we can do about it? |
Hey. So, I don't know the project well to state facts, so here are my guesses: In that case user can use spring profiles (i.e test vs not test) to choose what bean configurations they choose. The goal would be making the @RabbitListenerTest work with the spring boot default config spring.main.allow-bean-definition-overriding=false. Does that make any sense? |
It makes sense for Boot users but it will break every application that uses I don't know if it's possible to make it conditional on whether Boot is present on the class path, but it could be difficult because we'd end up with circular dependencies. |
If nothing else, then this issue will at least appear in search results for people starting a new project with the test lib. So you are saying spring.main.allow-bean-definition-overriding=false is very much a spring-boot default, and won't make it into spring proper as default value? |
The problem is that if we, say, unconditionally set What is the difficulty of adding a @RabbitListenerTest
@TestPropertySource(properties = "spring.main.allow-bean-definition-overriding=true") |
In conclusion, I thought spring is advertising to not override beans now and this library (which is part of spring umbrella) does do that, so wanted to let you know. |
Good point; we'll take a look to see if there is something we can do to avoid this. |
Fixes spring-projects#914 * Rework `RabbitBootstrapConfiguration` into the `ImportBeanDefinitionRegistrar` and check for bean definitions presence it is going to register. This way an override from the `RabbitListenerTestBootstrap` is going to have a precedence and its `RabbitListenerTestHarness` won't allow a regular `RabbitListenerAnnotationBeanPostProcessor` to be registered * Rework `TestRabbitTemplate` to gather all the listener container from the `ContextRefreshedEvent` instead of the `SmartInitializingSingleton`. Looks like Spring doesn't care about their order, therefore we need to be sure that `RabbitListenerAnnotationBeanPostProcessor` has populated its `registry` with containers before. * Demonstrate that `allowBeanDefinitionOverriding = false` works well now in the `ExampleRabbitListenerCaptureTest` * Optimize `checkTestConfigs` and `updateCopyrights` Gradle tasks for their `inputs` and `outputs` for better `UP-TO-DATE` handling **Cherry-pick to 2.1.x without `build.gradle` changes**
* GH-914: Honor AllowBeanDefOverriding = false Fixes #914 * Rework `RabbitBootstrapConfiguration` into the `ImportBeanDefinitionRegistrar` and check for bean definitions presence it is going to register. This way an override from the `RabbitListenerTestBootstrap` is going to have a precedence and its `RabbitListenerTestHarness` won't allow a regular `RabbitListenerAnnotationBeanPostProcessor` to be registered * Rework `TestRabbitTemplate` to gather all the listener container from the `ContextRefreshedEvent` instead of the `SmartInitializingSingleton`. Looks like Spring doesn't care about their order, therefore we need to be sure that `RabbitListenerAnnotationBeanPostProcessor` has populated its `registry` with containers before. * Demonstrate that `allowBeanDefinitionOverriding = false` works well now in the `ExampleRabbitListenerCaptureTest` * Optimize `checkTestConfigs` and `updateCopyrights` Gradle tasks for their `inputs` and `outputs` for better `UP-TO-DATE` handling **Cherry-pick to 2.1.x without `build.gradle` changes** * * Fix typo in the `ExampleRabbitListenerCaptureTest`
* GH-914: Honor AllowBeanDefOverriding = false Fixes #914 * Rework `RabbitBootstrapConfiguration` into the `ImportBeanDefinitionRegistrar` and check for bean definitions presence it is going to register. This way an override from the `RabbitListenerTestBootstrap` is going to have a precedence and its `RabbitListenerTestHarness` won't allow a regular `RabbitListenerAnnotationBeanPostProcessor` to be registered * Rework `TestRabbitTemplate` to gather all the listener container from the `ContextRefreshedEvent` instead of the `SmartInitializingSingleton`. Looks like Spring doesn't care about their order, therefore we need to be sure that `RabbitListenerAnnotationBeanPostProcessor` has populated its `registry` with containers before. * Demonstrate that `allowBeanDefinitionOverriding = false` works well now in the `ExampleRabbitListenerCaptureTest` * Optimize `checkTestConfigs` and `updateCopyrights` Gradle tasks for their `inputs` and `outputs` for better `UP-TO-DATE` handling **Cherry-pick to 2.1.x without `build.gradle` changes** * * Fix typo in the `ExampleRabbitListenerCaptureTest`
Fixed in 2.1.5.BUILD-SNAPSHOT - thanks for persevering! |
This was the fastest issue to fix time I've seen for third party library. High five to both of you. |
I am using:
spring boot 2.1.2.RELEASE
spring-rabbit-2.1.3.RELEASE
spring-rabbit-test-2.1.3.RELEASE
When running tests I get an error:
The bean 'org.springframework.amqp.rabbit.config.internalRabbitListenerAnnotationProcessor', defined in class path resource [org/springframework/amqp/rabbit/test/RabbitListenerTestBootstrap.class], could not be registered. A bean with that name has already been defined in class path resource [org/springframework/amqp/rabbit/annotation/RabbitBootstrapConfiguration.class] and overriding is disabled.
Spring suggests to use "spring.main.allow-bean-definition-overriding=true" to override the default behaviour and it does work. However, I find it a bit bad solution to change global spring configuration.
There is also possibility that I am doing something wrong.
The text was updated successfully, but these errors were encountered: