1. 27 5月, 2012 4 次提交
    • C
      Cache by-type lookups in DefaultListableBeanFactory · 4c7a1c0a
      Chris Beams 提交于
      Prior to this change, by-type lookups using DLBF#getBeanNamesForType
      required traversal of all bean definitions within the bean factory
      in order to inspect their bean class for assignability to the target
      type. These operations are comparatively expensive and when there are a
      large number of beans registered within the container coupled with a
      large number of by-type lookups at runtime, the performance impact can
      be severe. The test introduced here demonstrates such a scenario clearly.
      
      This performance problem is likely to manifest in large Spring-based
      applications using non-singleton beans, particularly request-scoped
      beans that may be created and wired many thousands of times per second.
      
      This commit introduces a simple ConcurrentHashMap-based caching strategy
      for by-type lookups; container-wide assignability checks happen only
      once on the first by-type lookup and are afterwards cached by type
      with the values in the map being an array of all bean names assignable
      to that type. This means that at runtime when creating and autowiring
      non-singleton beans, the cost of by-type lookups is reduced to that of
      ConcurrentHashMap#get.
      
      Issue: SPR-6870
      4c7a1c0a
    • C
      Polish · db1cb134
      Chris Beams 提交于
      Issue: SPR-6870
      db1cb134
    • C
      Reduce log level for message re: missing annotation · f55a4a1a
      Chris Beams 提交于
      Previously (since Spring 3.1.1) RecursiveAnnotationAttributesVisitor
      logs at level WARN when ASM parsing encounters an annotation or an (enum
      used within an annotation) that cannot be classloaded. This is not
      necessarily indicative of an error, e.g. JSR-305 annotations such as
      @Nonnull may be used only for static analysis purposes, but because
      these annotations have runtime retention, they remain present in the
      bytecode. Per section 9.6.1.2 of the JLS, "An annotation that is present
      in the binary may or may not be available at run-time via the reflective
      libraries of the Java platform."
      
      This commit lowers the log level of these messages from warn to debug,
      but leaves at warn level other messages dealing with the ability
      reflectively read enum values from within annotations.
      
      Issue: SPR-9233
      f55a4a1a
    • C
      Support not (!) operator for profile selection · bcd44f37
      Chris Beams 提交于
      The following syntax is now supported
      
        <beans profile="p1,!p2">
      
        @Profile("p1", "!p2")
      
      indicating that the <beans> element or annotated component should
      be processed only if profile 'p1' is active or profile 'p2' is not
      active.
      
      Issue: SPR-8728
      bcd44f37
  2. 26 5月, 2012 6 次提交
    • C
      Merge branch cbeams/SPR-9439 · e72c49f4
      Chris Beams 提交于
      * SPR-9439:
        Introduce ConfigurableWebEnvironment
        Introduce ConfigurableEnvironment#merge
        Polish
      e72c49f4
    • C
      Introduce ConfigurableWebEnvironment · 2a2b6eef
      Chris Beams 提交于
      Changes introduced in Spring 3.1 for Environment support inadvertently
      established a cyclic dependency between the
      org.springframework.web.context and
      org.springframework.web.context.support packages, specifically through
      web.context.ContextLoader's invocation of
      web.context.support.WebApplicationContextUtils#initServletPropertySources.
      
      This commit introduces ConfigurableWebEnvironment to break this cyclic
      dependency. All web.context.ConfigurableWebApplicationContext types now
      return web.context.ConfigurableWebEnvironment from their #getEnvironment
      methods; web.context.support.StandardServletEnvironment now implements
      ConfigurableWebEnvironment and makes the call to
      web.context.support.WebApplicationContextUtils#initServletPropertySources
      within its implementation of #initPropertySources. This means that
      web.context.ContextLoader now invokes
      web.context.ConfigurableWebEnvironment#initPropertySources instead of
      web.context.support.WebApplicationContextUtils#initServletPropertySources
      and thus the cycle is broken.
      
      Issue: SPR-9439
      2a2b6eef
    • C
      Introduce ConfigurableEnvironment#merge · 9fcfd7e8
      Chris Beams 提交于
      Prior to this change, AbstractApplicationContext#setParent replaced the
      child context's Environment with the parent's Environment if available.
      This has the negative effect of potentially changing the type of the
      child context's Environment, and in any case causes property sources
      added directly against the child environment to be ignored. This
      situation could easily occur if a WebApplicationContext child had a
      non-web ApplicationContext set as its parent. In this case the parent
      Environment type would (likely) be StandardEnvironment, while the child
      Environment type would (likely) be StandardServletEnvironment. By
      directly inheriting the parent environment, critical property sources
      such as ServletContextPropertySource are lost entirely.
      
      This commit introduces the concept of merging an environment through
      the new ConfigurableEnvironment#merge method. Instead of replacing the
      child's environment with the parent's,
      AbstractApplicationContext#setParent now merges property sources as
      well as active and default profile names from the parent into the
      child. In this way, distinct environment objects are maintained with
      specific types and property sources preserved. See #merge Javadoc for
      additional details.
      
      Issue: SPR-9444, SPR-9439
      9fcfd7e8
    • C
      Polish · 5874383e
      Chris Beams 提交于
      Issue: SPR-9439
      5874383e
    • C
      Fix package cycle in @EnableSpringConfigured · 5327a7a3
      Chris Beams 提交于
      @EnableSpringConfigured and its @Import'ed
      SpringConfiguredConfiguration @Configuration class inadvertently
      established a package cycle between beans.factory.aspectj and
      context.annotation due to SpringConfiguredConfiguration's
      dependency on annotations such as @Configuration, @Bean and @Role.
      
      This commit fixes this architecture bug by moving
      @EnableSpringConfigured and SpringConfiguredConfiguration from the
      beans.factory.aspectj package to the context.annotation package where
      they belong.
      
      This change is assumed to be very low impact as @EnableSpringConfigured
      was introduced in 3.1.0 and relocation is happening as quickly as
      possible in 3.1.2. @EnableSpringConfigured is assumed to be infrequently
      used at this point, and for those that are the migration path
      is straightforward. When upgrading from Spring 3.1.0 or 3.1.1, update
      import statements in any affected @Configuration classes to reflect the
      new packaging.
      
      Issue: SPR-9441
      5327a7a3
    • C
      Introduce BeanFactoryAnnotationUtils · a4b00c73
      Chris Beams 提交于
      Commit 096693c4 refactored and
      deprecated TransactionAspectUtils, moving its #qualifiedBeanOfType
      and related methods into BeanFactoryUtils. This created a package cycle
      between beans.factory and beans.factory.annotation due to use of the
      beans.factory.annotation.Qualifier annotation in these methods.
      
      This commit breaks the package cycle by introducing
      beans.factory.annotation.BeanFactoryAnnotationUtils and moving these
      @Qualifier-related methods to it. It is intentionally similar in name
      and style to the familiar BeanFactoryUtils class for purposes of
      discoverability.
      
      There are no backward-compatibilty concerns associated with this change
      as the cycle was introduced, caught and now fixed before a release.
      
      Issue: SPR-6847
      a4b00c73
  3. 24 5月, 2012 1 次提交
    • R
      Merge rather than add URI vars to data binding values · 4027b389
      Rossen Stoyanchev 提交于
      As of Spring 3.1 URI variables can be used for data binding purposes in
      addition to request parameters (including query string and form params)
      
      In some cases URI variables and request params can overlap (e.g. form
      contains a child entity with an entityId as hidden form input while the
      URI contains the entityId of the parent entity) and that can lead to
      surprises if the application already exists.
      
      This change ensures that request parameters are used first and URI
      vars are added only if they don't overlap. Ideally however an
      application should not use the same uri variable name as the name of
      a request parameter where they don't refer to the same value.
      
      Issue: SPR-9349
      4027b389
  4. 22 5月, 2012 5 次提交
    • C
      Merge branch cbeams/SPR-7022 · 5330c52e
      Chris Beams 提交于
      * SPR-7022:
        Support initial delay attribute for scheduled tasks
        Polish scheduled task execution infrastructure
      5330c52e
    • C
      Support initial delay attribute for scheduled tasks · 53673d6c
      Chris Beams 提交于
      java.util.concurrent's ScheduledExecutorService and its #schedule*
      methods allow for an 'initialDelay' parameter in milliseconds.
      Similarly, Spring's TaskExecutor abstraction allows for a concrete
      'startTime' expressed as a Date. However, Spring's <task:scheduled> XML
      element and @Scheduled annotation have, to date, not allowed for an
      initial delay parameter that can be propagated down to the underlying
      TaskScheduler/ScheduledExecutorService.
      
      This commit introduces initial-delay and #initialDelay attributes to
      task:scheduled and @Scheduled respectively, both indicating the number
      of milliseconds to wait before the first invocation of the method in
      question. Specifying a delay in this fashion is only valid in
      conjunction with fixed-rate and fixed-delay tasks (i.e. not with cron
      or trigger tasks).
      
      The principal changes required to support these new attributes lie in
      ScheduledTaskRegistrar, which previously supported registration of
      tasks in the form of a Runnable and a Long parameter indicating (in the
      case of fixed-rate and fixed-delay tasks), the interval with which the
      task should be executed. In order to accommodate a third (and optional)
      'initialDelay' parameter, the IntervalTask class has been added as a
      holder for the Runnable to be executed, the interval in which to run
      it, and the optional initial delay. For symmetry, a TriggerTask and
      CronTask have also been added, the latter subclassing the former. And a
      'Task' class has been added as a common ancestor for all the above.
      
      One oddity of the implementation is in the naming of the new
      setters in ScheduledTaskRegistrar. Prior to this commit, the setters
      were named #setFixedDelayTasks, #setFixedRateTasks, etc, each accepting
      a Map<Runnable, long>. In adding new setters for each task type, each
      accepting a List<IntervalTask>, List<CronTask> etc, naturally the
      approach would be to use method overloading and to introduce methods
      of the same name but with differing parameter types. Unfortunately
      however, Spring does not support injection against overloaded methods
      (due to fundamental limitations of the underlying JDK Introspector).
      This is not a problem when working with the ScheduledTaskRegistrar
      directly, e.g. from within a @Configuration class that implements
      SchedulingConfigurer, but is a problem from the point of view of the
      ScheduledTasksBeanDefinitionParser which parses the <task:scheduled>
      element - here the ScheduledTaskRegistrar is treated as a Spring bean
      and is thus subject to these limitations. The solution to this problem
      was simply to avoid overloading altogether, thus the naming of the new
      methods ending in "List", e.g. #setFixedDelayTasksList, etc. These
      methods exist primarily for use by the BeanDefinitionParser and are
      not really intended for use by application developers. The Javadoc for
      each of the new methods makes note of this.
      
      Issue: SPR-7022
      53673d6c
    • C
      Polish scheduled task execution infrastructure · 4d5fe57a
      Chris Beams 提交于
      In anticipation of substantive changes required to implement "initial
      delay" support in the <task:scheduled> element and @Scheduled
      annotation, the following updates have been made to the components and
      infrastructure supporting scheduled task execution:
      
       - Fix code style violations
       - Fix compiler warnings
       - Add Javadoc where missing, update to use {@code} tags, etc.
       - Organize imports to follow conventions
      4d5fe57a
    • C
      Merge pull request #62 from poutsma/SPR-9300 · e2fbaa84
      Chris Beams 提交于
      * SPR-9300:
        Add convenient WebAppInitializer base classes
      e2fbaa84
    • A
      Add convenient WebAppInitializer base classes · f64c13ad
      Arjen Poutsma 提交于
      This commit introduces three abstract WebApplicationInitializers, to be
      used in the typical setup of a Spring-based web application.
      
       - AbstractContextLoaderInitializer provides an abstract base class for
         registering a ContextLoaderListener.
      
       - AbstractDispatcherServletInitializer provides an abstract base class
         for registering a DispatcherServlet, with an optional root context.
      
       - AbstractAnnotationConfigDispatcherServletInitializer provides an
         abstract base class for registering a DispatcherServlet and optional
         ContextLoaderListener based on annotated (e.g. @Configuration)
         classes.
      
      Issue: SPR-9300
      f64c13ad
  5. 21 5月, 2012 1 次提交
  6. 20 5月, 2012 4 次提交
    • C
      Merge branch cbeams/SPR-6847 · 1d060013
      Chris Beams 提交于
      * SPR-6847:
        Support executor qualification with @Async#value
        Polish async method execution infrastructure
        Refactor and deprecate TransactionAspectUtils
      1d060013
    • C
      Support executor qualification with @Async#value · ed0576c1
      Chris Beams 提交于
      Prior to this change, Spring's @Async annotation support was tied to a
      single AsyncTaskExecutor bean, meaning that all methods marked with
      @Async were forced to use the same executor. This is an undesirable
      limitation, given that certain methods may have different priorities,
      etc. This leads to the need to (optionally) qualify which executor
      should handle each method.
      
      This is similar to the way that Spring's @Transactional annotation was
      originally tied to a single PlatformTransactionManager, but in Spring
      3.0 was enhanced to allow for a qualifier via the #value attribute, e.g.
      
        @Transactional("ptm1")
        public void m() { ... }
      
      where "ptm1" is either the name of a PlatformTransactionManager bean or
      a qualifier value associated with a PlatformTransactionManager bean,
      e.g. via the <qualifier> element in XML or the @Qualifier annotation.
      
      This commit introduces the same approach to @Async and its relationship
      to underlying executor beans. As always, the following syntax remains
      supported
      
        @Async
        public void m() { ... }
      
      indicating that calls to #m will be delegated to the "default" executor,
      i.e. the executor provided to
      
        <task:annotation-driven executor="..."/>
      
      or the executor specified when authoring a @Configuration class that
      implements AsyncConfigurer and its #getAsyncExecutor method.
      
      However, it now also possible to qualify which executor should be used
      on a method-by-method basis, e.g.
      
        @Async("e1")
        public void m() { ... }
      
      indicating that calls to #m will be delegated to the executor bean
      named or otherwise qualified as "e1". Unlike the default executor
      which is specified up front at configuration time as described above,
      the "e1" executor bean is looked up within the container on the first
      execution of #m and then cached in association with that method for the
      lifetime of the container.
      
      Class-level use of Async#value behaves as expected, indicating that all
      methods within the annotated class should be executed with the named
      executor. In the case of both method- and class-level annotations, any
      method-level #value overrides any class level #value.
      
      This commit introduces the following major changes:
      
       - Add @Async#value attribute for executor qualification
      
       - Introduce AsyncExecutionAspectSupport as a common base class for
         both MethodInterceptor- and AspectJ-based async aspects. This base
         class provides common structure for specifying the default executor
         (#setExecutor) as well as logic for determining (and caching) which
         executor should execute a given method (#determineAsyncExecutor) and
         an abstract method to allow subclasses to provide specific strategies
         for executor qualification (#getExecutorQualifier).
      
       - Introduce AnnotationAsyncExecutionInterceptor as a specialization of
         the existing AsyncExecutionInterceptor to allow for introspection of
         the @Async annotation and its #value attribute for a given method.
         Note that this new subclass was necessary for packaging reasons -
         the original AsyncExecutionInterceptor lives in
         org.springframework.aop and therefore does not have visibility to
         the @Async annotation in org.springframework.scheduling.annotation.
         This new subclass replaces usage of AsyncExecutionInterceptor
         throughout the framework, though the latter remains usable and
         undeprecated for compatibility with any existing third-party
         extensions.
      
       - Add documentation to spring-task-3.2.xsd and reference manual
         explaining @Async executor qualification
      
       - Add tests covering all new functionality
      
      Note that the public API of all affected components remains backward-
      compatible.
      
      Issue: SPR-6847
      ed0576c1
    • C
      Polish async method execution infrastructure · 3fb11870
      Chris Beams 提交于
      In anticipation of substantive changes required to implement @Async
      executor qualification, the following updates have been made to the
      components and infrastructure supporting @Async functionality:
      
       - Fix trailing whitespace and indentation errors
       - Fix generics warnings
       - Add Javadoc where missing, update to use {@code} tags, etc.
       - Avoid NPE in AopUtils#canApply
       - Organize imports to follow conventions
       - Remove System.out.println statements from tests
       - Correct various punctuation and grammar problems
      3fb11870
    • C
      Refactor and deprecate TransactionAspectUtils · 096693c4
      Chris Beams 提交于
      TransactionAspectUtils contains a number of methods useful in
      retrieving a bean by type+qualifier. These methods are functionally
      general-purpose save for the hard coding of PlatformTransactionManager
      class literals throughout.
      
      This commit generifies these methods and moves them into
      BeanFactoryUtils primarily in anticipation of their use by async method
      execution interceptors and aspects when performing lookups for qualified
      executor beans e.g. via @Async("qualifier").
      
      The public API of TransactionAspectUtils remains backward compatible;
      all methods within have been deprecated, and all calls to those methods
      throughout the framework refactored to use the new BeanFactoryUtils
      variants instead.
      096693c4
  7. 19 5月, 2012 4 次提交
    • S
      Doc. usage of JSR-250 lifecycle annotations in TCF · e71cd06a
      Sam Brannen 提交于
      The reference manual previously did not mention the applicability of
      JSR-250 lifecycle annotations within the TestContext framework. The
      lacking documentation here has lead to misunderstandings of the support
      provided for @PostConstruct and @PreDestroy in test classes.
      
      The testing chapter of the reference manual has therefore been updated
      to explicitly define the limited support for these annotations.
      
      Also introduced Jsr250LifecycleTests for empirical verification of the 
      expected behavior.
      
      Issue: SPR-4868
      e71cd06a
    • R
      Fix issue with resolution of WebDataBinder argument · 03d6350e
      Rossen Stoyanchev 提交于
      There is usually not need to put annotations on a WebDataBinder
      argument in an `@InitBinder` method. However, the presence of any
      annotation prevented the successful resolution of the argument.
      This fix addresses the issue.
      
      Issue: SPR-8946
      03d6350e
    • S
      Update @Bean Javadoc re: 'lite' mode, scope, etc. · 5cd6543d
      Sam Brannen 提交于
      Updated the "@Bean Lite Mode" section in order to properly document 
      scoping and lifecycle semantics.
      
      Also fleshed out the discussion of the non-applicability of 'inter-bean 
      references' in lite mode.
      
      Issue: SPR-9425
      5cd6543d
    • S
      Verify scope support for 'lite' @Beans in the TCF · dc6b2abe
      Sam Brannen 提交于
      Introduced AtBeanLiteModeScopeTests integration tests to verify proper 
      scoping of beans created in 'lite' mode.
      
      Updated comments in TACCWithoutACTests to better reflect the runtime 
      behavior for 'lite' @Bean methods.
      
      Issue: SPR-9401
      dc6b2abe
  8. 18 5月, 2012 11 次提交
    • S
      Polish doc for 'annotated class' support in TCF · 49966258
      Sam Brannen 提交于
      Revised the content in the @ContextConfiguration annotation section.
      
      Issue: SPR-9401
      49966258
    • C
      Merge branch garyrussell/SPR-9249 · 6a01ca6d
      Chris Beams 提交于
      * SPR-9249:
        Add value-type attrib to beans->map->entry element
      6a01ca6d
    • G
      Add value-type attrib to beans->map->entry element · 183ac0c1
      Gary Russell 提交于
      Previously, the <value> subelement of a map <entry> allowed one to
      specify the type of a specific map entry value. This patch allows a
      value-type attribute as well, such that instead of the following
      syntax
      
          <entry key="x-message-ttl">
              <value type="java.lang.Long">100</value>
          </entry>
          <entry key="x-ha-policy" value="all" />
      
      one can now use the more concise form
      
          <entry key="x-message-ttl" value="100" value-type="java.lang.Long"/>
          <entry key="x-ha-policy" value="all"/>
      
      The new value-type attribute may be used at the <map> level as well,
      indicating that all elements are of the same type.
      
      Appropriate tests have been added exercising value-type at the <map> and
      <entry> levels.
      
      Issue: SPR-9249
      183ac0c1
    • C
      Update spring.schemas to reflect 3.2 schemas · f3bcb6e2
      Chris Beams 提交于
      Commit 180c5b2e introduced 3.2 versions
      of all spring-* schemas; this commit updates spring.schemas mapping
      files to include these new versions.
      f3bcb6e2
    • S
      Update documentation of 'annotated class' support in the TCF · 504cdf49
      Sam Brannen 提交于
      Updated the testing chapter of the reference manual to refer to 
      'annotated classes' instead of 'configuration classes' where 
      appropriate.
      
      Also revised the content and examples in the @ContextConfiguration 
      annotation section, mentioned Gradle, and reformatted the entire text.
      
      Issue: SPR-9401
      504cdf49
    • S
      Delete superfluous fail() invocations in RequestResponseBodyMethodProcessorTests · 09d98fd3
      Sam Brannen 提交于
      Several test methods in RequestResponseBodyMethodProcessorTests
      are currently annotated with @test(expected=…) and additionally contain:
      
          fail("Expected exception");
      
      This combination is superfluous, and the unnecessary fail() invocations
      have therefore been removed.
      09d98fd3
    • R
      Add required flag to @RequestBody · 77ae1014
      Rossen Stoyanchev 提交于
      If true and there is no body => HttpMessageNotReadableException
      If false and there is no body, the argument resolves to null.
      
      Issue: SPR-9239
      77ae1014
    • R
      Decode path vars in pre-3.1 `@mvc` support clases too · 0105c5eb
      Rossen Stoyanchev 提交于
      See the commit comments for:
      https://github.com/SpringSource/spring-framework/commit/57307a0b2e5bce8f70d5deddf8df11d034dc8c5a
      
      This commit also applies the change to pre-3.1 `@mvc` suppor classes.
      
      Issue: SPR-6951
      0105c5eb
    • R
      Decode path vars when url decoding is turned off · 57307a0b
      Rossen Stoyanchev 提交于
      When URL decoding is turned off in AbstractHandlerMapping, the
      extracted path variables are also not encoded. Turning off URL decoding
      may be necessary for request mapping to work correctly when the path
      may contain the (encoded) special character '/'. At the same time there
      is no good reason not to leave path variables encoded. This change
      ensures path variables are encoded when URL decoding is turned off.
      
      Issue: SPR-9098
      57307a0b
    • S
      Improve documentation of annotated class support in the TCF · 36e7cb2d
      Sam Brannen 提交于
      Updated all Javadoc in the Spring TestContext Framework (TCF) to explain
      and refer to 'annotated classes' instead of 'configuration classes'.
      
      Specifically, @ContextConfiguration now explicitly defines what is meant
      by 'annotated classes', and various other classes now refer to this
      definition. Otherwise, the term 'configuration class' has simply been
      replaced with 'annotated class'.
      
      Also deleted cross references to deprecated JUnit 3.8 classes and
      formatted Javadoc in general for greater readability.
      
      Issue: SPR-9401
      36e7cb2d
    • S
      Polish recent changes to Log4jWebConfigurer · 59e3223c
      Sam Brannen 提交于
      Reordered inline comments so that they now apply to current
      state of the code.
      
      Added logger entry in testlog4j.properties to avoid console
      warning.
      
      Issue: SPR-9417
      59e3223c
  9. 17 5月, 2012 4 次提交
    • C
      Merge pull request #42 from sslavic/SPR-5369 · 98bf01ad
      Chris Beams 提交于
      * SPR-5369:
        Fix circular placeholder prevention
      98bf01ad
    • S
      Fix circular placeholder prevention · 18006c72
      Stevo Slavic 提交于
      A set of resolved placeholder references is used for circular
      placeholder prevention. For complex property definitions this mechanism
      would put property values with unresolved inner placeholder references
      in the set, but would try to remove property values with placeholders
      resolved, leaving the set in an invalid state and the mechanism broken.
      
      This fix makes sure that the value that is put in the set is same one
      that is removed from it, and by doing so avoids false positives in
      reporting circular placeholders.
      
      Issue: SPR-5369
      18006c72
    • C
      Merge pull request #34 from marschall/warnings · f667db56
      Chris Beams 提交于
      * warnings:
        Fix compiler warnings
      f667db56
    • P
      Fix compiler warnings · 13239a0c
      Philippe Marschall 提交于
      This patch fixes several compiler warnings that do not point to code
      problems. Two kinds of warnings are fixed. First in a lot of cases
      @SuppressWarnings("unchecked") is used although there are no unchecked
      casts happening. This seems to be a leftover from when the code base
      was on Java 1.4, now that the code base was moved to Java 1.5 these are
      no longer necessary. Secondly there some places where the raw types of
      List and Class are used where there wildcard types (List<?> and
      Class<?>) would work just as well without causing any raw type warnings.
      
      These changes are beneficial particularly when working in Eclipse or
      other IDEs because it reduces 'noise', helping to isolate actual
      potential problems in the code.
      
      The following changes have been made:
      
       - remove @SuppressWarnings where no longer needed
      
       - use wildcard types instead of raw types where possible
      13239a0c