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

Support @Configuration as a meta-annotation in the TestContext framework [SPR-12659] #17259

Closed
spring-issuemaster opened this issue Jan 23, 2015 · 1 comment

Comments

Projects
None yet
2 participants
@spring-issuemaster
Copy link
Collaborator

commented Jan 23, 2015

Artem Bilan opened SPR-12659 and commented

Status Quo

The case with Spring Boot to reproduce:

@SpringApplicationConfiguration
@RunWith(SpringJUnit4ClassRunner.class)
public class MyTests {

	@SpringBootApplication
	public static class ContextConfiguration {

	}
}

Since @SpringBootApplication is meta-annotated with @Configuration there should be no reason to explicitly declare @Configuration, but right now it is a necessary workaround in order to allow AnnotationConfigContextLoaderUtils.isDefaultConfigurationClassCandidate() to detect @Configuration on the nested static ContextConfiguration class. The reason is that AnnotationConfigContextLoaderUtils invokes clazz.isAnnotationPresent(Configuration.class) which does not search for meta-annotations.


Deliverables

  1. Refactor isDefaultConfigurationClassCandidate() in AnnotationConfigContextLoaderUtils so that it detects the presence of @Configuration when used indirectly as a meta-annotation.

Affects: 4.0 GA

Referenced from: commits 2d91838, 0c856b3

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Jan 23, 2015

Sam Brannen commented

Completed as described in GitHub commits 2d91838 (4.2) and 0c856b3 (4.1.5):

Support @Configuration as meta-annotation in the TCF

Spring Framework 4.0 introduced support for using test-related
annotations as meta-annotations in the Spring TestContext Framework
(TCF) in order to create custom composed annotations within a test
suite; however, the detection of default @Configuration classes in test
classes was not updated to search for @Configuration declared as a
meta-annotation. Specifically, AnnotationConfigContextLoaderUtils
invokes Class.isAnnotated() which only searches for annotations
declared directly on the class in question.

This commit addresses this issue by refactoring the
isDefaultConfigurationClassCandidate() method in
AnnotationConfigContextLoaderUtils so that it uses
AnnotationUtils.findAnnotation() instead of Class.isAnnotated() for
detecting the presence of the @Configuration annotation, either
directly or as a meta-annotation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.