You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Enable reuse of DefaultActiveProfilesResolver [SPR-12611] #17212
I want to write a custom profile resolver for @ActiveProfiles.
The profile resolution logic is to dynamically append profiles on top of profiles resolved by default logic. Since it is appending profiles, I wanted to either extend or delegate to the DefaultActiveProfilesResolver class to reuse the default logic.
publicclassMyProfileResolverextendsDefaultActiveProfilesResolver {
@OverridepublicString[] resolve(Class<?> testClass) {
String[] profiles = super.resolve(testClass);
// my logic to append profiles
}
}
However, in DefaultActiveProfilesResolver, there is this check logic:
Class<? extendsActiveProfilesResolver> resolverClass = annAttrs.getClass("resolver");
if (!ActiveProfilesResolver.class.equals(resolverClass)) {
Stringmsg = String.format("Configuration error for test class [%s]: %s cannot be used "
+ "in conjunction with custom resolver [%s].", rootDeclaringClass.getName(),
getClass().getSimpleName(), resolverClass.getName());
logger.error(msg);
thrownewIllegalStateException(msg);
}
Basically, this check logic prevents the reuse of the DefaultActiveProfilesResolver class.
Proposal
Can this check can be removed, or should this check be isAssignableFrom() instead of equals()?
Tadaya Tsuyukubo, this was a use case that I did not foresee when I wrote that check. So thanks for bringing it to my attention.
After a cursory review of the changes introduced in conjunction with #14588, I believe that it should be possible to simply get rid of that check altogether.
In order to allow DefaultActiveProfilesResolver to be reused (e.g., via
extension or delegation), the check which asserts that the 'resolver'
attribute of @ActiveProfiles is not set to a customer resolver class
has been removed.
Activity
spring-projects-issues commentedon Jan 10, 2015
Sam Brannen commented
Tadaya Tsuyukubo, this was a use case that I did not foresee when I wrote that check. So thanks for bringing it to my attention.
After a cursory review of the changes introduced in conjunction with #14588, I believe that it should be possible to simply get rid of that check altogether.
Regards,
Sam
spring-projects-issues commentedon Jan 10, 2015
Sam Brannen commented
Completed as described in GitHub commit 276712d:
spring-projects-issues commentedon Jan 10, 2015
Sam Brannen commented
Backported to Spring Framework 4.1.5: a76a650