Skip to content

Preserve 'reader' attribute in @ImportResource hierarchies [SPR-6327] #10993

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

Closed
spring-projects-issues opened this issue Nov 10, 2009 · 1 comment
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) status: declined A suggestion or change that we don't feel we should currently apply type: enhancement A general enhancement

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Nov 10, 2009

Chris Beams opened SPR-6327 and commented

Status Quo

Currently, either of the following work fine:

@Configuration
@ImportResource(
    locations = "com/foo/config.xml",
    reader = XmlBeanDefinitionReader.class)
public class ConfigA { }

@Configuration
@ImportResource(
    locations = "com/foo/config.properties",
    reader = PropertiesBeanDefinitionReader.class)
public class ConfigB { }

However, the following will not work:

@Configuration
@ImportResource(
    locations = "com/foo/config.properties",
    reader = PropertiesBeanDefinitionReader.class)
public class ConfigB extends ConfigA { }

Analysis

Problem: the XML file specified in ConfigA will be read by the PropertiesBeanDefinitionReader declared in ConfigB, which naturally fails.

Cause: when parsing annotations from the @Configuration class hierarchy, the last reader attribute wins, effectively overriding any other reader attributes from classes up the hierarchy.

Solution: crawl the class/annotation hierarchy manually and build up a context containing every resource and its associated BeanDefinitionReader type, analogous to the support for loader in @ContextConfiguration in the Spring TestContext Framework (TCF).

This is similar in concept to the way that TCF operates. In this way, this improvement will make sense to implement alongside #10976, which deals with support for relative paths and import-by-convention semantics -- features that are also supported by TCF.


Issue Links:

Referenced from: commits ae11387

@spring-projects-issues
Copy link
Collaborator Author

Chris Beams commented

See TODO in @Ignored test for this feature with in ImportResourceTests.testImportDifferentResourceTypes().

@spring-projects-issues spring-projects-issues added status: declined A suggestion or change that we don't feel we should currently apply type: enhancement A general enhancement in: core Issues in core modules (aop, beans, core, context, expression) labels Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) status: declined A suggestion or change that we don't feel we should currently apply type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants