Closed
Description
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:
- Support relative and by-convention use of @ImportResource [SPR-6310] #10976 Support relative and by-convention use of
@ImportResource
- XML import should support patterns for relative paths as well [SPR-5015] #9690 XML import should support patterns for relative paths as well