Skip to content

ContextLoader is supplied composed annotation class instead of test class for default resource detection [SPR-11455] #16081

Closed
@spring-projects-issues

Description

@spring-projects-issues

Dave Syer opened SPR-11455 and commented

Overview

I guess it all works when the annotation is @ContextConfiguration but when it is a composed annotation (i.e., an annotation meta-annotated with @ContextConfiguration) then the test framework all goes a bit haywire. I think if this bug were fixed then custom annotations composed with @ContextConfiguration would pick up the default context locations or configuration classes automatically. As things stand they don't, and there's no workaround as far as I can tell.

Analysis

ContextConfigurationAttributes has a declaringClass attribute that looks as if it is supposed to contain the test class. ContextLoaderUtils.resolveContextConfigurationAttributes(Class) loses that information somehow, maybe by using the declaringClass instead of the rootDeclaringClass of the AnnotationDescriptor it is working with, or maybe because the ContextConfigurationAttributes needs a new property for the rootDeclaringClass (my guess is the former because who would need the meta-annotation class)?

Further Analysis

The same problem applies to the @ContextHierarchy processing code, and a similar problem exists for the invocation of ActiveProfilesResolver instances (see #16093).

Consequences

One consequence is that there is no way for a ContextLoader (or SmartContextLoader) to access the declaring test class to discover default resource locations or configuration classes when @ContextConfiguration is used as a meta-annotation.


Affects: 4.0 GA

Attachments:

Issue Links:

Metadata

Metadata

Assignees

Labels

in: testIssues in the test moduletype: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions