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

Relative imports in @Configuration classes [SPR-8356] #13003

Closed
spring-projects-issues opened this issue May 19, 2011 · 1 comment
Closed

Relative imports in @Configuration classes [SPR-8356] #13003

spring-projects-issues opened this issue May 19, 2011 · 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 May 19, 2011

Keith Donald opened SPR-8356 and commented

The following @Configuration class declared in package com.springsource.greenhouse.config, which uses imports, could be simplified from:

@Configuration
@ComponentScan("com.springsource.greenhouse")
@Import({ComponentConfig.Embedded.class, ComponentConfig.Standard.class})
public class ComponentConfig {
	
	/**
	 * Properties to support the 'embedded' mode of operation.
	 */
	@Configuration
	@Profile("embedded")
	@PropertySource("classpath:com/springsource/greenhouse/config/embedded.properties")
        static class Embedded {
	}

	/**
	 * Properties to support the 'standard' mode of operation.
	 */
	@Configuration
	@Profile("standard")
	@PropertySource("classpath:application.properties")
        static class Standard {
	}
}

to something like:

@Configuration
@ComponentScan("${topLevelPackage}")
@Import({ComponentConfig.Embedded.class, ComponentConfig.Standard.class})
public class ComponentConfig {
	
	/**
	 * Properties to support the 'embedded' mode of operation.
	 */
	@Configuration
	@Profile("embedded")
	@PropertySource("embedded.properties") <!-- Class-relative import- ->
        static class Embedded {
	}

	/**
	 * Properties to support the 'standard' mode of operation.
	 */
	@Configuration
	@Profile("standard")
	@PropertySource("/application.properties") <!-- Absolute class-path path -->
        static class Standard {
	}

}

This would make things more concise, future-proof to refactoring changes, and consistent with how beans:import tag works (imported resources there are relative to the location of the enclosing resource).

Also, it seems imports are now webapp-root relative for web applications. I'm not so sure this is desirable, since these are @Configuration classes in the classpath. I would expect imports to always be classpath resources unless an alternative resource loading scheme was used.


Issue Links:

@spring-projects-issues
Copy link
Collaborator Author

Chris Beams commented

re-introduce formatting accidentally stripped out earlier.

@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