Commit Graph

4239 Commits

Author SHA1 Message Date
Chris Beams 2b4328023e Improve ApplicationContextInitializer sorting
ContextLoader and FrameworkServlet now use
AnnotationAwareOrderComparator to support @Order usage; previously
supported only implementation of the Ordered interface.
2011-05-30 12:55:33 +00:00
Chris Beams 2eea63eec5 Introduce Framework/DispatcherServlet constructors
Constructors have been added to both FrameworkServlet and
DispatcherServlet to support instance-based programmatic registration
of Servlets within ServletContainerInitializer implementations in
Servlet 3.0+ environments, and more particularly when using Spring 3.1's
WebApplicationInitializer SPI.

This change also renames the method added to FrameworkServlet in
SPR-8185 from #initializeWebApplicationContext to #applyInitializers.
The reason being that a method named #initWebApplicationContext was
already present and the names overlapped confusingly.

Issue: SPR-7672, SPR-8185
2011-05-30 12:54:48 +00:00
Chris Beams c4d98278e9 Fix DispatcherServlet warnings 2011-05-30 12:54:24 +00:00
Chris Beams fb9fb00c04 Update GenericWAC to implement ConfigurableWAC
GenericWebApplicationContext now implements
ConfigurableWebApplicationContext in order to be compatible with
Framework/DispatcherServlet and ContextLoader/Listener, especially with
regard to changes in SPR-7672 that allow for programmatic use of these
types within Servlet 3.0+ environments.  For the first time, it's now
reasonable to imagine injecting a GWAC into DispatcherServlet; the most
robust way to accommodate this possibility is for GWAC to implement
CWAC.

The implementation is in name only, allowing for interchangable use of
GWAC anywhere, for example, an XWAC could otherwise go.  Methods such
as setConfigLocation will throw UnsupportedOperationException if the
configLocation value actually contains text.  Other methods are
implemented as no-ops or to throw UOE as appropriate.

Issue: SPR-7672
2011-05-30 12:53:57 +00:00
Chris Beams c9e67b2ef2 Introduce Servlet 3.0 WebApplicationInitializer
WebApplicationInitializer provides a programmatic alternative to the
traditional WEB-INF/web.xml servlet container deployment descriptor
for Servlet API 3.0+ environments.

This is done by building atop the new ServletContainerInitializer
support in Servlet 3.0. See SpringServletContainerInitializer for
complete details. And see WebApplicationInitializer Javadoc for
typical usage examples.

Issue: SPR-7672
2011-05-30 12:53:32 +00:00
Juergen Hoeller 2b51759113 fixed reflective class names 2011-05-29 22:00:14 +00:00
Juergen Hoeller 788a65b8e7 compatibility with Quartz 2.0 variant of the JobFactory interface 2011-05-29 21:45:19 +00:00
Juergen Hoeller 8e169a2782 updated Quartz scheduling package to support Quartz 1.8 as well 2011-05-29 21:29:40 +00:00
Juergen Hoeller f1b9b8e924 preparations for 3.1 M2 release 2011-05-29 20:55:44 +00:00
Juergen Hoeller e1d9457b7d CustomNumberEditor generically declares numberClass as subclass of Number (matching NumberUtils) 2011-05-29 20:55:15 +00:00
Juergen Hoeller 0d69b80385 polishing 2011-05-29 20:53:34 +00:00
Juergen Hoeller 98c6a2784f RemoteExporter uses an opaque proxy for 'serviceInterface' exposure (no AOP interfaces exposed) 2011-05-29 20:52:37 +00:00
Juergen Hoeller a966cba97f fixed JPA 2.0 timeout hints to correctly specify milliseconds (SPR-8086) 2011-05-29 20:52:03 +00:00
Juergen Hoeller c303b22e30 updated IntelliJ dependency descriptors 2011-05-29 20:43:52 +00:00
Juergen Hoeller af8aff3e49 added StandardServletMultipartResolver for Servlet 3.0 2011-05-29 20:38:23 +00:00
Rossen Stoyanchev 127115671c SPR-8218 MVC chapter updates 2011-05-27 17:09:53 +00:00
Chris Beams 367a0c2933 Upgrade javax.servlet dependency to 3.0 for .web
In support of SPR-7672 which will support code-based configuration
alternatives to web.xml using new features in the Servlet 3.0 API.

This upgrade does *not* force Spring users to upgrade to Servlet 3.0
capable containers.  Compatibility with and support for
javax.servlet >= 2.4 remains.

Issue: SPR-7672
2011-05-26 13:34:21 +00:00
Chris Beams 2ceeff370a Allow multiple locations via @PropertySource#value
Issue: SPR-8314
2011-05-25 10:52:25 +00:00
Chris Beams 0756a6abfe Polish PropertySource and Environment Javadoc 2011-05-25 10:52:03 +00:00
Arjen Poutsma 37d955b35b Added tests for @RequestMaping produces and consumes 2011-05-25 09:21:44 +00:00
Keith Donald f43d0e1003 Revised converter search algorithm to favor super classes before interface hierarchy 2011-05-24 22:20:54 +00:00
Keith Donald ad93d20a6c SPR-6749 2011-05-24 19:40:14 +00:00
Keith Donald 47e3f0948d polish 2011-05-24 18:32:01 +00:00
Keith Donald 01cbfd4f6f added null binding check for primitives for all conversion results; polishing 2011-05-24 17:53:18 +00:00
Rossen Stoyanchev c5833b192e SPR-7353 Use canWrite to narrow down list of producible types 2011-05-24 17:22:22 +00:00
Keith Donald d02e37a307 added new ConverterRegistry operation; polishing 2011-05-24 03:47:50 +00:00
Keith Donald e25fbf2533 added symmetry to ToString converters: SPR-8306 2011-05-23 23:00:43 +00:00
Sam Brannen e11d7c328f Added Eclipse project dependency on org.springframework.asm 2011-05-23 17:18:14 +00:00
Chris Beams c4363673dc Delegate parent environment to child app contexts
Calls to AbstractApplicationContext#setParent delegate the parent
context environment to the child.

This ensures that any property sources added to the parent are available
to the child as well as ensuring that any profiles activated are
activated everywhere.

Child contexts may still choose to replace their environment (through an
ApplicationContextInitializer, for example).  In any case, however, in
the root/child web application context relationship established by
ContextLoader + DispatcherServlet, the child is guaranteed to have
already been given the parent environment by the time it is delegated
to any ACIs.

See AbstractApplicationContext#setParent for implementation

See FrameworkServlet#createWebApplicationContext for order in which
setParent then initializeWebApplicationContext are called.

Issue: SPR-8185
2011-05-23 10:04:00 +00:00
Chris Beams c696e195fa Introduce AnnotationConfigCapableApplicationContext
AnnotationConfigApplicationContext and
AnnotationConfigWebApplicationContext both expose #register and #scan
methods as of the completion of SPR-8320. This change introduces a new
interface that declares each of these methods and refactors ACAC and
ACWAC to implement it.

Beyond information value, this is useful for implementors of the
ApplicationContextInitializer interface, in that users may create an ACI
that works consistently across ACAC and ACWAC for standalone (e.g.
testing, batch) or web (e.g. production) use.

Issue: SPR-8365,SPR-8320
2011-05-23 10:03:23 +00:00
Chris Beams e128ee2464 Introduce AnnotationConfigWAC #scan and #register
Primarily for use in conjunction with ApplicationContextInitializer,
these new #scan and #register methods mirror those in
AnnotationConfigApplicationContext. #setConfigLocation
and #setConfigLocations methods remain for compatibility with
ContextLoader-style initialization, but have been locally overridden
and documented clearly.

AnnotationConfigWebApplicationContext#loadBeanDefinitions Javadoc has
also been updated to explain the processing logic for each of these
potential inputs.

Issue: SPR-8320
2011-05-23 10:02:50 +00:00
Chris Beams 56720fc42c Support "contextInitializerClasses" init-param
FrameworkServlet now has support equivalent to ContextLoader and its
"contextInitializerClasses" context-param introduced in 3.1 M1.

This allows users to specify ApplicationContextInitializers at the root
(ContextLoader) level and/or at the DispatcherServlet level.

Issue: SPR-8366
2011-05-23 10:02:18 +00:00
Chris Beams 3c6254df90 Polish FrameworkServlet Javadoc; fix warnings 2011-05-23 10:01:49 +00:00
Keith Donald 7430fcd904 SPR-8364 2011-05-23 07:38:27 +00:00
Keith Donald 5c67dbf424 revised findCommonElement handling within TypeDescriptor.forObject(Object); we now fully introspect the collection elements to resolve the common type. We also support nested introspection e.g. collections of collections. Object.class is used to indicate no common type, and TypeDescriptor.NULL is used to indicate a null element value 2011-05-23 05:21:02 +00:00
Keith Donald 79f9d1cfc6 moved applyIndexedObject internal, now invoked inside forObject static factory method 2011-05-23 01:08:18 +00:00
Keith Donald 4d6a5849f7 SPR-8364 2011-05-22 19:10:40 +00:00
Chris Beams 4a6101a697 Guard against null in #visitInnerClass
Issue: SPR-8358,SPR-8186
2011-05-21 01:39:50 +00:00
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