Commit Graph

4051 Commits

Author SHA1 Message Date
Chris Beams 95b1dbadb0 Register nested @Configuration classes automatically
The following is now possible:

@Configuration
public class AppConfig {
    @Inject DataSource dataSource;

    @Bean
    public MyBean myBean() {
        return new MyBean(dataSource);
    }

    @Configuration
    static class DatabaseConfig {
        @Bean
        DataSource dataSource() {
            return new EmbeddedDatabaseBuilder().build();
        }
    }
}

public static void main(String... args) {
    AnnotationConfigApplicationContext ctx =
        new AnnotationConfigApplicationContext(AppConfig.class);
    ctx.getBean(MyBean.class);     // works
    ctx.getBean(DataSource.class); // works
}

Notice that the @Import annotation was not used and that only AppConfig
was registered against the context. By virtue of the fact that
DatabaseConfig is a member class of AppConfig, it is automatically
registered when AppConfig is registered. This avoids an awkward and
redundant @Import annotation when the relationship is already implicitly
clear.

See @Configuration Javadoc for details.

Issue: SPR-8186
2011-05-21 01:20:33 +00:00
Chris Beams 5b2c7c4e58 Introduce ClassMetadata#getMemberClassNames
ClassMetadata implementations can now introspect their member (nested)
classes. This will allow for automatic detection of nested
@Configuration types in SPR-8186.

Issue: SPR-8358,SPR-8186
2011-05-21 01:20:03 +00:00
Chris Beams 76e3d2855a Polish @Configuration-related Javadoc 2011-05-21 01:19:25 +00:00
Rossen Stoyanchev 5fa7f24794 SPR-7353 Respect 'produces' condition in ContentNegotiatingViewResolver, improve selection of more specific media type in a pair 2011-05-20 17:02:20 +00:00
Chris Beams c481d2e9fb Rename {Default=>Standard}PortletEnvironment
Issue: SPR-8348
2011-05-20 03:57:35 +00:00
Chris Beams f893b62a9b Rename {DefaultWeb=>StandardServlet}Environment
Issue: SPR-8348
2011-05-20 03:55:56 +00:00
Chris Beams c06752ef72 Rename {Default=>Standard}Environment
Issue: SPR-8348
2011-05-20 03:53:37 +00:00
Chris Beams 615fcff7ae Polish Environment-related Javadoc 2011-05-20 03:50:41 +00:00
Chris Beams 7271ba8182 Introduce AbstractEnvironment#customizePropertySources
This new hook in the AbstractEnvironment lifecycle allows for more
explicit and predictable customization of property sources by
subclasses.  See Javadoc and existing implementations for detail.

Issue: SPR-8354
2011-05-20 03:50:14 +00:00
Chris Beams c4a13507f0 Introduce reserved default profile support
AbstractEnvironment and subclasses now register a reserved default
profile named literally 'default' such that with no action on the part
of the user, beans defined against the 'default' profile will be
registered - if no other profiles are explicitly activated.

For example, given the following three files a.xml, b.xml and c.xml:

    a.xml
    -----
    <beans> <!-- no 'profile' attribute -->
        <bean id="a" class="com.acme.A"/>
    </beans>

    b.xml
    -----
    <beans profile="default">
        <bean id="b" class="com.acme.B"/>
    </beans>

    c.xml
    -----
    <beans profile="custom">
        <bean id="c" class="com.acme.C"/>
    </beans>

bootstrapping all of the files in a Spring ApplicationContext as
follows will result in beans 'a' and 'b', but not 'c' being registered:

    ApplicationContext ctx = new GenericXmlApplicationContext();
    ctx.load("a.xml");
    ctx.load("b.xml");
    ctx.load("c.xml");
    ctx.refresh();
    ctx.containsBean("a"); // true
    ctx.containsBean("b"); // true
    ctx.containsBean("c"); // false

whereas activating the 'custom' profile will result in beans 'a' and
'c', but not 'b' being registered:

    ApplicationContext ctx = new GenericXmlApplicationContext();
    ctx.load("a.xml");
    ctx.load("b.xml");
    ctx.load("c.xml");
    ctx.getEnvironment().setActiveProfiles("custom");
    ctx.refresh();
    ctx.containsBean("a"); // true
    ctx.containsBean("b"); // false
    ctx.containsBean("c"); // true

that is, once the 'custom' profile is activated, beans defined against
the the reserved default profile are no longer registered. Beans not
defined against any profile ('a') are always registered regardless of
which profiles are active, and of course beans registered
against specific active profiles ('c') are registered.

The reserved default profile is, in practice, just another 'default
profile', as might be added through calling env.setDefaultProfiles() or
via the 'spring.profiles.default' property.  The only difference is that
the reserved default is added automatically by AbstractEnvironment
implementations.  As such, any call to setDefaultProfiles() or value set
for the 'spring.profiles.default' will override the reserved default
profile.  If a user wishes to add their own default profile while
keeping the reserved default profile as well, it will need to be
explicitly redeclared, e.g.:

    env.addDefaultProfiles("my-default-profile", "default")

The reserved default profile(s) are determined by the value returned
from AbstractEnvironment#getReservedDefaultProfiles().  This protected
method may be overridden by subclasses in order to customize the
set of reserved default profiles.

Issue: SPR-8203
2011-05-20 03:49:15 +00:00
Chris Beams 415057c184 Remove AbstractEnvironment#getPropertyResolver
Method is obsolete now that Environment (thus AbstractEnvironment as
well) implements the ConfigurablePropertyResolver interface.
2011-05-20 03:48:19 +00:00
Chris Beams 818467b9e5 Consolidate Environment tests 2011-05-20 03:47:48 +00:00
Rossen Stoyanchev 0bf92782ea SPR-8352 Init and apply MappedInterceptors from AbstractHandlerMapping 2011-05-19 16:45:25 +00:00
Arjen Poutsma 60aa598c03 SPR-8296 - Extension for CastorMarshaller - additional unmarshaller properties 2011-05-19 14:01:35 +00:00
Arjen Poutsma dd8a9cce05 SPR-8295 - Extension for CastorMarshaller - additional marshaller properties 2011-05-19 13:34:36 +00:00
Rossen Stoyanchev 5ac2e4418f SPR-8350 ContentNegotiatingViewResolver initialization for nested ViewResolvers 2011-05-19 13:07:15 +00:00
Rossen Stoyanchev 100fed47f3 SPR-7353 Doc update for consumes/produces + changelog update 2011-05-19 13:05:53 +00:00
Costin Leau b39673aa79 revised cache abstraction
- removed generics from Cache/CacheManager (they add no value since it's an SPI not API)
+ update docs and tests
+ renamed ConcurrentCacheFactoryBean to ConcurrentMapCacheFactoryBean
2011-05-18 18:34:41 +00:00
Costin Leau dadd0f57ee revised cache abstraction
- removed AbstractDelegatingCache (a cache is not a map, no need to offer a template)
+ renamed ConcurrentCache to ConcurrentCacheMap
2011-05-18 17:43:13 +00:00
Arjen Poutsma 1eaca65720 @RequestMapping.consumes() and produces() now default to an empty array, instead of */* 2011-05-18 11:34:47 +00:00
Arjen Poutsma a618bcc8cd Exposing HttpServletRequest/Response in ServletServerHttpRequest/Response 2011-05-18 11:24:57 +00:00
Chris Beams 4520ea8690 Revert #processConfigBeanDefinitions to 3.0.x API
Revert signature of
ConfigurationClassPostProcessor#processConfigBeanDefinitions to its form
found in the 3.0.x line.  Refactorings made during 3.1 development
caused otherwise package-private types such as
ConfigurationClassBeanDefinitionReader to escape through this public
method, causing issues for STS as well as being a general design issue.

Upon review, the refactorings could easily be backed out in favor of a
simpler approach, and this has been done.

This also means that ConfigurationClassBeanDefinitionReader can return
to package-private visibility, and this change has been made as well.

Issue: SPR-8200
2011-05-18 08:53:46 +00:00
Chris Beams 6fcea8b99d Remove ConfigurationClassParser from public API
Issue: SPR-8200
2011-05-17 19:15:17 +00:00
Costin Leau 8dfcae535e revise cache API
+ update failing test
2011-05-17 18:16:07 +00:00
Costin Leau 0eb40e1e5e revise cache API
+ update failing test
2011-05-17 18:01:35 +00:00
Costin Leau dea1fc933f revise cache API
+ update failing AJ test
2011-05-17 17:35:01 +00:00
Costin Leau 861e481755 revise cache API
+ update failing test
2011-05-17 17:09:49 +00:00
Costin Leau 3699a037a5 revise cache API
+ add missing files (remember to check "show unversioned files")
2011-05-17 16:58:15 +00:00
Costin Leau 0b917e3f9c revise cache API
- eliminate unneeded methods
+ introduced value wrapper (name still to be decided) to avoid cache race conditions
+ improved name consistency
2011-05-17 16:50:00 +00:00
Rossen Stoyanchev af1dfd3577 Use request attribute to check producible media types when writing to the response body 2011-05-17 13:02:48 +00:00
Arjen Poutsma 1bbdb0d2ff minor fix. 2011-05-17 12:22:21 +00:00
Arjen Poutsma b0a4be7cd1 Only respect RequestMappingInfos that have a pattern match in handleNoMatch 2011-05-17 10:07:36 +00:00
Arjen Poutsma ad2e0d4587 SPR-7353 - @ResponseBody and returned HttpEntity now respect @RequestMapping.produces() 2011-05-17 09:45:57 +00:00
Rossen Stoyanchev 57c757afc5 SPR-2692 Update mvc chapter with URI template support in redirect: view names 2011-05-16 13:24:42 +00:00
Oliver Gierke d14d82612d SPR-8336 - Fixed broken test case.
Converted the test to JUnit 4.
2011-05-14 06:44:51 +00:00
Oliver Gierke f8bf8742e1 SPR-8336 - Added constructor to AnnotationTypeFilter to allow matching interfaces as well.
Reviewed by Chris.
2011-05-14 06:22:44 +00:00
Rossen Stoyanchev 1784df8d3e SPR-6996 Add mvc:interceptor bean references 2011-05-13 18:06:55 +00:00
Costin Leau 700a02b094 SPR-8334
+ commit missing configs
2011-05-13 16:09:33 +00:00
Costin Leau cc519e7c6d SPR-8334
+ commit missing configs
2011-05-13 15:59:22 +00:00
Rossen Stoyanchev 5c0e22e7a8 SPR-8289 Ensure BeanNameUrlHandlerMapping and default HandlerAdapters are never 'turned off' through the MVC namespaces 2011-05-13 15:46:37 +00:00
Costin Leau 4dd5ae16b2 SPR-8256
+ fix small doc typo
2011-05-13 15:40:12 +00:00
Costin Leau a986d758e7 SPR-
+ remove duplicate class
2011-05-13 15:37:10 +00:00
Arjen Poutsma bb2cc8457f SPR-7353 - Added equivalent of JAX-RS @Produces to Spring MVC 2011-05-13 09:43:45 +00:00
Chris Beams a557878a6f Document @Autowired and @Value limitations
@Autowired, @Value and other annotations cannot be applied within
Spring Bean(Factory)PostProcessor types, because they themselves
are processed using BeanPostProcessors.  Javadoc and reference docs
have been updated to reflect.

Issue: SPR-4935, SPR-8213
2011-05-13 03:41:29 +00:00
Chris Beams df5bab3454 Remove "@BeanAge" from reference documentation
Issue: SPR-8327
2011-05-13 03:40:26 +00:00
Andy Clement f8a2dd3f65 SPR-8211: property accessor ordering correction and removal of unnecessary duplicates 2011-05-12 16:40:44 +00:00
Rossen Stoyanchev b46598965e Add method to allow further validation of request mapping infos at startup + other minor javadoc updates. 2011-05-12 15:03:36 +00:00
Chris Beams 2afeb08e3c Fix @Autowired+@PostConstruct+@Configuration issue
A subtle issue existed with the way we relied on isCurrentlyInCreation
to determine whether a @Bean method is being called by the container
or by user code.  This worked in most cases, but in the particular
scenario laid out by SPR-8080, this approach was no longer sufficient.

This change introduces a ThreadLocal that contains the factory method
currently being invoked by the container, such that enhanced @Bean
methods can check against it to see if they are being called by the
container or not.  If so, that is the cue that the user-defined @Bean
method implementation should be invoked in order to actually create
the bean for the first time.  If not, then the cached instance of
the already-created bean should be looked up and returned.

See ConfigurationClassPostConstructAndAutowiringTests for
reproduction cases and more detail.

Issue: SPR-8080
2011-05-12 12:28:13 +00:00
Chris Beams 57206db152 Refine ignored @PropertySource log warning
If the enclosing environment does not implement ConfigurableEnvironment,
then @PropertySource annotations are ignored because there is no way to
add them to the Environment. Now checking first to see if there are any
@PropertySource annotations present before issuing the warning.

Issue: SPR-8314
2011-05-12 12:27:14 +00:00
Arjen Poutsma 8190b4f70a Javadoc 2011-05-12 09:00:39 +00:00