-
Notifications
You must be signed in to change notification settings - Fork 627
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* GH-973: Higher order for RabbitListTestBootstrap Fixes #973 When we use `@EnableRabbit` and `@RabbitListenerTest` in the same configuration set, e.g. mixing real `@Configuration` and test one for `@RabbitListenerTest`, we may end up with the case when `@EnableRabbit` is processed before `@RabbitListenerTest`, so, `RabbitListenerTestHarness` bean is not going to appear in the application context. * Implement a `DeferredImportSelector` with an `@Order` for the `@EnableRabbit` as well as `RabbitListenerTest` giving higher order to the `RabbitListenerTestSelector`, so `RabbitListenerTestBootstrap` is processed and register its `RabbitListenerTestHarness` earlier, than it is done by the `RabbitBootstrapConfiguration` **Cherry-pick to 2.1.x** * * Fix Checkstyle * Add JavaDocs to new classes
- Loading branch information
1 parent
1333fda
commit c71ed1e
Showing
6 changed files
with
105 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
...t-test/src/main/java/org/springframework/amqp/rabbit/test/RabbitListenerTestSelector.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Copyright 2019 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.springframework.amqp.rabbit.test; | ||
|
||
import org.springframework.amqp.rabbit.annotation.RabbitListenerConfigurationSelector; | ||
import org.springframework.core.Ordered; | ||
import org.springframework.core.annotation.Order; | ||
import org.springframework.core.type.AnnotationMetadata; | ||
|
||
/** | ||
* A {@link RabbitListenerConfigurationSelector} extension to register | ||
* a {@link RabbitListenerTestBootstrap}, but already with the higher order, | ||
* so the {@link RabbitListenerTestHarness} bean is registered earlier, | ||
* than {@link org.springframework.amqp.rabbit.annotation.RabbitListenerAnnotationBeanPostProcessor}. | ||
* | ||
* @author Artem Bilan | ||
* | ||
* @since 2.1.6 | ||
*/ | ||
@Order(Ordered.LOWEST_PRECEDENCE - 100) | ||
public class RabbitListenerTestSelector extends RabbitListenerConfigurationSelector { | ||
|
||
@Override | ||
public String[] selectImports(AnnotationMetadata importingClassMetadata) { | ||
return new String[] { RabbitListenerTestBootstrap.class.getName() }; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
.../java/org/springframework/amqp/rabbit/annotation/RabbitListenerConfigurationSelector.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Copyright 2019 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.springframework.amqp.rabbit.annotation; | ||
|
||
import org.springframework.context.annotation.DeferredImportSelector; | ||
import org.springframework.core.annotation.Order; | ||
import org.springframework.core.type.AnnotationMetadata; | ||
|
||
/** | ||
* A {@link DeferredImportSelector} implementation with the lowest order to import a | ||
* {@link RabbitBootstrapConfiguration} as late as possible. | ||
* | ||
* @author Artem Bilan | ||
* | ||
* @since 2.1.6 | ||
*/ | ||
@Order | ||
public class RabbitListenerConfigurationSelector implements DeferredImportSelector { | ||
|
||
@Override | ||
public String[] selectImports(AnnotationMetadata importingClassMetadata) { | ||
return new String[] { RabbitBootstrapConfiguration.class.getName() }; | ||
} | ||
|
||
} |