Commit Graph

1126 Commits

Author SHA1 Message Date
Phillip Webb
a9290d80c4 Backport "Polish @Imports search code"
Issue: SPR-9925
Backport-Commit: 4cdf46f83c
Conflicts:
	spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassParser.java
2013-01-22 15:19:52 +01:00
Phillip Webb
1f52f09089 Backport "Ensure @Imports are processed in correct order"
Issue: SPR-9925
Backport-Commit: 3416e058a0
Conflicts:
	spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassParser.java
2013-01-22 15:17:46 +01:00
Phillip Webb
e9616b7204 Backport "Prevent duplicate @Import processing"
Refactor ConfigurationClassParser to recursively find values from
all @Import annotations, combining them into a single unique set.

This change prevents ImportBeanDefinitionRegistrars from being
invoked twice.

Issue: SPR-9925
Backport-Commit: 6d8b37d8bb
Conflicts:
	spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassParser.java
2013-01-22 15:15:25 +01:00
Phillip Webb
bbd5fc6f35 Backport "Polish Javadoc for @Import"
Issue: SPR-9925
Backport-Commit: e6c4840356
Conflicts:
	spring-context/src/main/java/org/springframework/context/annotation/Import.java
2013-01-22 15:12:56 +01:00
Juergen Hoeller
c374389a59 Added "exposeAccessContext" flag JndiRmiClientInterceptor/ProxyFactoryBean (for WebLogic)
Issue: SPR-9428
2013-01-18 16:51:52 +01:00
Juergen Hoeller
0c45f179b3 MBeanExporter does not log warnings for manually unregistered MBeans
Issue: SPR-9451
2013-01-18 14:43:39 +01:00
Juergen Hoeller
eb492ed583 SpringBeanAutowiringInterceptor eagerly releases BeanFactory if post-construction fails
Issue: SPR-10013
2013-01-18 14:13:35 +01:00
Juergen Hoeller
8135442336 Polishing 2013-01-15 22:09:52 +01:00
Juergen Hoeller
aa388bc094 Reintroduced "mode" and "proxy-target-class" attributes in spring-task-3.1.xsd
Issue: SPR-10177
2013-01-15 22:05:52 +01:00
Juergen Hoeller
7f7fbe8172 AbstractCacheManager accepts no caches defined, allowing for EHCache default cache setup
Issue: SPR-7955
2013-01-15 15:55:43 +01:00
Juergen Hoeller
9a04191c2b MessageSourceResourceBundle overrides JDK 1.6 containsKey method, avoiding NPE in getKeys
Issue: SPR-10136
2013-01-10 17:03:29 +01:00
Juergen Hoeller
b9ff29ec7e Revised NoOpCacheManager implementation (along with changes for 3.2 GA) 2012-12-13 00:07:16 +01:00
Juergen Hoeller
a551cbcf9d Marked all applicable fields as final (along with changes for 3.2 GA) 2012-12-13 00:06:00 +01:00
Juergen Hoeller
c207882fdc Removed unused cachedFieldValue (along with changes for 3.2 GA) 2012-12-13 00:05:05 +01:00
Juergen Hoeller
751c429897 Polishing 2012-12-12 03:31:18 +01:00
Juergen Hoeller
81348516ff Polishing 2012-12-11 20:41:31 +01:00
Juergen Hoeller
a00e00bd47 Fixed CGLIB proxy class leaks through further equals/hashCode implementations in Spring AOP pointcuts
Issue: SPR-8008
2012-12-11 20:37:42 +01:00
Juergen Hoeller
7384c3d82f ConfigurationClassPostProcessor consistently uses ClassLoader, not loading core JDK classes via ASM
Issue: SPR-10058
2012-12-05 19:12:38 +01:00
Juergen Hoeller
dd68fecbf2 Avoid wide locks in order to remove deadlock potential in case of multi-threaded singleton creation/destruction
Issue: SPR-10020
Issue: SPR-8471
2012-11-25 23:33:05 +01:00
Juergen Hoeller
667438ddb0 Polishing 2012-11-25 22:29:05 +01:00
Juergen Hoeller
0deacb9fa1 Oracle OC4J support will be deprecated in favor of Oracle WebLogic as of Spring 3.2 2012-11-25 21:04:06 +01:00
Juergen Hoeller
e491d990de Minor polishing 2012-10-31 02:10:11 +01:00
Juergen Hoeller
6d6eaf8506 Added test for custom async annotation 2012-10-31 02:09:26 +01:00
Gareth Davis
983e2ce64f Allow 'arg-type' matches against element body
Allow the body of 'arg-type' XML elements to be used as an alternative to
'match' attribute when defining a 'replace-method' in XML configuration.

This change has been introduced primarily to support the samples printed
in the Apress 'Pro Spring' book.

Issue: SPR-9812
Backport-Issue: SPR-9929
Backport-Commit: 0709c033a0
2012-10-28 11:52:22 -07:00
Phillip Webb
ea49c8b840 Polish whitespace 2012-10-28 11:13:46 -07:00
Phillip Webb
ced6bb4569 Prevent memory leaks with @Configuration beans
Refactor ConfigurationClassEnhancer to allow cglib caching of
generated classes.  Prior to this commit each enhanced @Configuration
class would consume permgen space when created.

The CallbackFilter and Callback Types are now defined as static final
members so that they can be shared by all enhancers.  Only the
callbackInstances remain specific to a @Configuration class and
these are not used by cglib as part of the cache key.

Issue: SPR-9851
Backport-Commit: c8061393fb
2012-10-24 19:12:03 +02:00
Juergen Hoeller
c90e2c6f10 Made AutoProxyCreatorTests less dependent on container's own interrogation of FactoryBeans
Issue: SPR-9857
2012-10-12 23:06:15 +02:00
Juergen Hoeller
506e9f50d0 LoadTimeWeaverAware beans are consistently being created early for JPA weaving to work reliably
Reverted change for @Bean methods that declare FactoryBean as their return type: The effects of trying to create the FactoryBean to find out about its implementation type are too far-reaching. It's better to recommend declaring a specific return type in the method signature if you want the container to specifically react to your implementation type.

Issue: SPR-9857
2012-10-12 22:56:08 +02:00
Juergen Hoeller
2564db2bfd LoadTimeWeaverAware beans are consistently being created early for JPA weaving to work reliably
Includes a change for factory methods that declare their return type as FactoryBean: When asked for a specific type match (e.g. LoadTimeWeaverAware), we do check early singleton instances as well (reusing the instances that we create for getObjectType checks). This is necessary in order to make @Bean method introspection as capable as XML bean definition introspection, even in case of the @Bean method using a generic FactoryBean declaration for its return type (instead of the FactoryBean impl class).

Issue: SPR-9857
2012-10-12 17:13:07 +02:00
Juergen Hoeller
679e122326 LoadTimeWeaverAware beans are consistently being created early for JPA weaving to work reliably
Includes a change for factory methods that declare their return type as FactoryBean: When asked for a specific type match (e.g. LoadTimeWeaverAware), we do check early singleton instances as well (reusing the instances that we create for getObjectType checks). This is necessary in order to make @Bean method introspection as capable as XML bean definition introspection, even in case of the @Bean method using a generic FactoryBean declaration for its return type (instead of the FactoryBean impl class).

Issue: SPR-9857
2012-10-12 16:22:11 +02:00
Juergen Hoeller
9862fbfc01 BeanWrapper does not fall back to String constructor if ConversionService attempt failed before
Issue: SPR-9865
2012-10-11 19:42:58 +02:00
Juergen Hoeller
b2fce2f254 Backported "Register environment in all bean factories in a hierarchy"
Issue: SPR-9756
Issue: SPR-9764
2012-10-10 23:33:50 +02:00
Juergen Hoeller
c81543e1a4 ResourceBundleMessageSource supports "defaultEncoding", "fallbackToSystemLocale", "cacheSeconds"
These features require Java 6 or higher due to their dependency on the ResourceBundle.Control class. To some degree, ResourceBundleMessageSource catches up with ReloadableResourceBundleMessageSource now. However, as noted in the javadoc, there are still severe limitations in the standard ResourceBundle class that justify an ongoing investment in our own ReloadableResourceBundleMessageSource (based on the Spring resource abstraction, with manual parsing of properties files).

Issue: SPR-7392
2012-09-26 16:46:25 +02:00
Juergen Hoeller
437ce9bb0e Calling cancel on a Future returned by a TaskScheduler works reliably now
Issue: SPR-9821
2012-09-25 13:54:33 +02:00
Juergen Hoeller
0f522cfe6a Calling cancel on a Future returned by a TaskScheduler works reliably now
Issue: SPR-9821
2012-09-25 12:07:06 +02:00
Juergen Hoeller
69f2496cd7 ImportAwareBeanPostProcessor registered with ROLE_INFRASTRUCTURE 2012-09-24 11:27:40 +02:00
Juergen Hoeller
c25cbe5522 @Import'ed configuration classes get properly registered in case of same class name (second try)
Issue: SPR-9243
2012-09-10 22:13:32 +02:00
Juergen Hoeller
bec5463640 @Import'ed configuration classes get properly registered in case of same class name
Issue: SPR-9243
2012-09-10 15:43:20 +02:00
Juergen Hoeller
a0d0b37d10 polishing 2012-09-06 19:00:01 +02:00
Juergen Hoeller
5a149e4600 @Import'ed configuration classes get properly registered in case of same class name
Issue: SPR-9243
2012-09-06 18:59:45 +02:00
Juergen Hoeller
19718700cf @Resource processing properly works with scoped beans and prototypes again
Issue: SPR-9627
2012-08-31 11:49:32 +02:00
Juergen Hoeller
a3bfa754fd MessageSourceSupport uses locale-specific MessageFormat cache for default messages
Issue: SPR-9607
2012-08-30 16:30:08 +02:00
Chris Beams
a387d13d5f Reflect 3.2=>3.1.2 backports in @since tags etc
Issue: SPR-9443, SPR-6847, SPR-9446, SPR-9444, SPR-9439, SPR-9302,
       SPR-9507, SPR-9238, SPR-9397, SPR-9406, SPR-9502
2012-06-27 23:09:14 +02:00
Dridi Boukelmoune
eed090e5f5 Fix scoped-proxy memory leak w/ @Resource injection
Prior to this change, request-scoped components having
@Resource-injected dependencies caused a memory leak in
DefaultListableBeanFactory#dependenciesForBeanMap.

Consider the following example:

    @Component
    @Scope(value="request", proxyMode=ScopedProxyMode.TARGET_CLASS)
    public class MyComponent {

        @Resource
        private HttpServletRequest request;

        // ...
    }

The bean name for "MyComponent" will end up being
'scopedTarget.myComponent', which will become a key in
the #dependenciesForBeanMap structure.

On the first request, the injected HttpServletRequest bean will be a
proxy and will internally have a bean name of the form
"$Proxy10@1a3a2a52". This name will be added to the Set value associated
with the 'scopedTarget.myComponent' entry in #dependenciesForBeanMap.

On the second request, the process will repeat, but the injected
HttpServletRequest will be a different proxy instance, thus having a
different identity hex string, e.g. "$Proxy10@5eba06ff". This name will
also be added to the Set value associated with the
'scopedTarget.myComponent' entry in #dependenciesForBeanMap, and this
is the source of the leak: a new entry is added to the set on each
request but should be added only once.

This commit fixes the leak by introducing caching to
CommonAnnotationBeanPostProcessor#ResourceElement similar to that already
present in AutowiredAnnotationBeanPostProcessor#AutowiredFieldElement
and #AutowiredMethodElement. Essentially, each ResourceElement instance
now tracks whether it has been created, caches the ultimate value to be
injected and returns it eagerly if necessary. Besides solving the memory
leak, this has the side effect of avoiding unnecessary proxy creation.

This fix also explains clearly why injection into request-scoped
components using @Autowired never suffered this memory leak: because the
correct caching was already in place. Because @Resource is considerably
less-frequently used than @Autowired, and given that this particular
injection arrangement is relatively infrequent, it becomes
understandable how this bug has been present without being reported
since the introduction of @Resource support in Spring 2.5: developers
were unlikely to encounter it in the first place; and if they did, the
leak was minor enough (adding strings to a Set), that it could
potentially go unnoticed indefinitely depending on request volumes and
available memory.

Issue: SPR-9363
Backport-Issue: SPR-9176
Backport-Commit: f779c199ea
2012-06-27 23:09:13 +02:00
Chris Beams
a76c7ca299 Test meta-@Async executor qualification
Prove that Async#value is respected even when using @Async as a meta
annotation.

Issue: SPR-9443
Backport-Issue: SPR-6847
Backport-Commit: 37e024c6eb
2012-06-27 23:06:54 +02:00
Chris Beams
8bab873107 Support executor qualification with @Async#value
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-9443
Backport-Issue: SPR-6847
Backport-Commit: ed0576c181
2012-06-27 23:06:54 +02:00
Chris Beams
e8006bdf78 Polish async method execution infrastructure
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

Issue: SPR-9443
Backport-Issue: SPR-6847
Backport-Commit: 3fb11870d9
2012-06-27 23:06:05 +02:00
Chris Beams
20f87ab98d Introduce ConfigurableEnvironment#merge
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-9446
Backport-Issue: SPR-9444, SPR-9439
Backport-Commit: 9fcfd7e827
2012-06-27 23:06:04 +02:00
Juergen Hoeller
5875695d99 polishing 2012-05-28 00:11:55 +02:00
Juergen Hoeller
dcb44264ad EhCacheFactoryBean applies listeners and enabled/disabled flags to existing cache regions as well (SPR-9392) 2012-05-28 00:11:19 +02:00