559 Commits

Author SHA1 Message Date
Spring Buildmaster
63bff1f068 Increment version to 3.1.5.BUILD-SNAPSHOT 2013-01-23 15:00:13 +01:00
Spring Buildmaster
e7d2ac4427 Release version 3.1.4.RELEASE 2013-01-23 14:58:18 +01:00
Juergen Hoeller
50ed863279 EntityManagerFactoryUtils finds default EntityManagerFactory in parent contexts as well
Also introduces consistent use of getBean(Class) for similar use cases across the framework, accepting a locally unique target bean even if further matching beans would be available in parent contexts (in contrast to BeanFactoryUtils.beanOfType's behavior).

Issue: SPR-10160
2013-01-22 20:39:23 +01:00
Chris Beams
a3161632dd Backport "Use ExtendedBeanInfo on an as-needed basis only"
Prior to this change, CachedIntrospectionResults delegated to
ExtendedBeanInfo by default in order to inspect JavaBean
PropertyDescriptor information for bean classes.

Originally introduced with SPR-8079, ExtendedBeanInfo was designed to
go beyond the capabilities of the default JavaBeans Introspector in
order to support non-void returning setter methods, principally to
support use of builder-style APIs within Spring XML. This is a complex
affair, and the non-trivial logic in ExtendedBeanInfo has led to various
bugs including regressions for bean classes that do not declare
non-void returning setters.

Many of these issues were fixed when overhauling non-void JavaBean write
method support in SPR-10029, however it appears that some extremely
subtle issues may still remain. ExtendedBeanInfo was taken out of use
completely in the 3.2.x line with SPR-9677 and the new BeanInfoFactory
mechanism. This support was not backported to 3.1.x, however, in the
interest of stability.

This commit, then, inlines the conditional logic introduced by
BeanInfoFactory directly into CachedIntrospectionResults. The net effect
is that ExtendedBeanInfo is out of the code path entirely except for
bean classes that actually contain 'candidate' methods, i.e. non-void
and/or static write methods.

This commit also includes the changes made in SPR-10115.

Issue: SPR-9723, SPR-10029, SPR-9677, SPR-8079
2013-01-21 19:44:18 +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
ebbcc4d9fb CachedIntrospectionResults.clearClassLoader(null) removes cached classes for the system class loader
Issue: SPR-9189
2013-01-16 10:24:44 +01:00
Chris Beams
aa3e0be1a0 Handle non-void write methods deterministically
This change resolves a specific issue with processing
java.math.BigDecimal via ExtendedBeanInfo. BigDecimal has a particular
constellation of #setScale methods that, prior to this change, had the
potential to cause ExtendedBeanInfo to throw an IntrospectionException
depending on the order in which the methods were processed.

Because JDK 7 no longer returns deterministic results from
Class#getDeclaredMethods, it became a genuine possibility - indeed a
statistical certainty that the 'wrong' setScale method handling order
happens sooner or later. Typically one could observe this failure once
out of every four test runs.

This commit introduces deterministic method ordering of all discovered
non-void returning write methods in such a way that solves the problem
for BigDecimal as well as for any other class having a similar method
arrangement.

Also:

 - Remove unnecessary cast

 - Pass no method information to PropertyDescriptor superclasses when
   invoking super(...). This ensures that any 'type mismatch'
   IntrospectionExceptions are handled locally in ExtendedBeanInfo and
   its Simple* PropertyDescriptor variants where we have full control.

Issue: SPR-10111, SPR-9702
2012-12-20 02:16:07 +01:00
Juergen Hoeller
12c4f8e7f9 Polishing 2012-12-13 00:07:36 +01:00
Juergen Hoeller
2b4e25b6f3 Fixed typos in javadoc 2012-11-29 23:11:04 +01:00
Juergen Hoeller
9929810610 Removed accidentally added DestructionAwareAttributeHolder class 2012-11-29 23:09:24 +01:00
Juergen Hoeller
bed2134736 CachedIntrospectionResults uses full WeakReference for any non-safe ClassLoader arrangement
Previously, CachedIntrospectionResults had three modes of caching, with the intermediate mode relying on WeakReferences in the JDK PropertyDescriptor implementation. Since the JDK is actually using SoftReferences there these days, losing information in case of a GC run with tough memory constraints, we want to allow for hard references in PropertyDescriptor objects and therefore use a full WeakReference for the CachedIntrospectionResults object itself.

Issue: SPR-10028
2012-11-25 23:36:59 +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
Chris Beams
0ee12563b0 Overhaul non-void JavaBean write method support
This change revisits the implementation of ExtendedBeanInfo, simplifying
the overall approach while also ensuring that ExtendedBeanInfo is fully
isolated from the BeanInfo instance it wraps. This includes any existing
PropertyDescriptors in the wrapped BeanInfo - along with being copied
locally into ExtendedBeanInfo, each property descriptor is now also
wrapped with our own new "simple" PropertyDescriptor variants that
bypass the soft/weak reference management that goes on in both
java.beans.PropertyDescriptor and java.beans.IndexedPropertyDescriptor,
maintaining hard references to methods and bean classes instead. This
ensures that changes we make to property descriptors, e.g. adding write
methods, do not cause subtle conflicts during garbage collection (as was
reported and reproduced in SPR-9702).

Eliminating soft/weak reference management means that we must take extra
care to ensure that we do not cause ClassLoader leaks by maintaining
hard references to methods, and therefore transitively to the
ClassLoader in which the bean class was loaded. The forthcoming
SPR-10028 addresses this aspect.

See the updated ExtendedBeanInfo Javadoc for further details.

Issue: SPR-8079, SPR-8175, SPR-8347, SPR-8432, SPR-8491, SPR-8522,
       SPR-8806, SPR-8931, SPR-8937, SPR-8949, SPR-9007, SPR-9059,
       SPR-9414, SPR-9453, SPR-9542, SPR-9584, SPR-9677, SPR-9702,
       SPR-9723, SPR-9943, SPR-9978, SPR-10028, SPR-10029
Backport-Commit: 4a8be69099
Conflicts:
	spring-beans/src/main/java/org/springframework/beans/ExtendedBeanInfoFactory.java
2012-11-25 13:08:20 +01:00
Spring Buildmaster
e0b29b708c Increment version to 3.1.4.BUILD-SNAPSHOT 2012-10-31 18:14:06 +01:00
Spring Buildmaster
6c36240055 Release version 3.1.3.RELEASE 2012-10-31 18:12:45 +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
Juergen Hoeller
2ab55414e5 Polishing 2012-10-12 23:07:10 +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
13edc93f78 Only cache by-type lookups if configuration has been marked as frozen
Issue: SPR-9448
2012-10-12 16:44:04 +02:00
Juergen Hoeller
ee8e178434 Only cache by-type lookups if configuration has been marked as frozen
Issue: SPR-9448
2012-10-12 16:24:52 +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
d7825586dc Provider injection into prototype beans works for method parameters as well
Issue: SPR-9630
2012-10-11 19:39:37 +02:00
Juergen Hoeller
baeac9ea6b Polishing 2012-10-10 14:28:18 +02:00
Chris Beams
e70119733a Avoid further 'type mismatch' errors in ExtendedBeanInfo
This change fixes further cases under JDK 6 in which setting a bridged
(e.g. String-returning) read method can conflict with an existing
corresponding bridge write method that accepts an Object parameter.

This appears to be a implementation difference between JDKs 6 and 7,
where the JDK 6 Introspector adds bridge methods and JDK 7 does not.

The solution here is to consistently null-out any existing write method
before setting the read method. We were doing this elsewhere in
ExtendedBeanInfo already, but these two changes make the approach
consistent throuhout.

Issue: SPR-8806
Backport-Commit: 0c0a563a24
2012-10-09 20:16:30 -07:00
Sam Brannen
0824746255 Update Javadoc in ExtendedBeanInfo
- updated the link to the "indexed properties" section of the JavaBeans
   tutorial
2012-10-09 20:16:30 -07:00
Chris Beams
30d0bd309c Address various ExtendedBeanInfo bugs
- Ensure that ExtendedBeanInfoTests succeeds when building under JDK 7

 - Improve handling of read and write method registration where
   generic interfaces are involved, per SPR-9453

 - Add repro test for SPR-9702, in which EBI fails to register
   an indexed read method under certain circumstances

Issue: SPR-9778
Backport-Issue: SPR-9702, SPR-9414, SPR-9453
Backport-Commit: b50bb5071a
2012-10-09 20:15:54 -07:00
Juergen Hoeller
b79260a017 Fixed potential race condition in concurrent calling of autowired methods on a prototype bean
Autowired methods might have been skipped on subsequent creation of further bean instances due to the 'skip' flag set to false outside of the synchronized block, with another thread entering the block and setting the flag to true in the meantime.

Issue: SPR-9806
2012-09-25 12:50:10 +02:00
Juergen Hoeller
7ebfd9e6a8 BeanFactoryAnnotationUtils throws NoSuchBeanDefinitionExceptions instead of IllegalStateExceptions
Issue: SPR-9652
2012-09-10 15:26:27 +02:00
Juergen Hoeller
f9147d375f Expression detection properly handles cached String literals
Issue: SPR-9670
2012-09-10 11:10:16 +02:00
Juergen Hoeller
33463a94e3 refined TypeConverterDelegate's ConversionService exception handling
Issue: SPR-9498
2012-09-05 01:00:10 +02:00
Juergen Hoeller
cb13353c1d don't make assumptions about equality if ConversionService has failed
Issue: SPR-9498
2012-09-04 18:04:02 +02:00
Juergen Hoeller
fbe955ab28 @Autowired-driven ObjectFactory/Provider resolution works in non-singleton beans as well
Issue: SPR-9181
2012-08-31 15:58:41 +02:00
Juergen Hoeller
26ee0c4842 aligned with recent changes in CommonAnnotationBeanPostProcessor; backported NPE check
Issue: SPR-9176
Issue: SPR-9627
Issue: SPR-9316
2012-08-31 11:55:10 +02:00
Spring Buildmaster
671f97721f Increment version to 3.1.3.BUILD-SNAPSHOT 2012-07-07 20:05:06 +02:00
Spring Buildmaster
49f728eae8 Release version 3.1.2.RELEASE 2012-07-07 17:13:55 +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
Chris Beams
841d9533db Cache by-type lookups in DefaultListableBeanFactory
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-9448
Backport-Issue: SPR-6870
Backport-Commit: 4c7a1c0a54
2012-06-27 23:09:14 +02:00
Chris Beams
0d18deb6a4 Polish
Issue: SPR-9448
Backport-Issue: SPR-6870
Backport-Commit: db1cb13448
2012-06-27 23:09:14 +02:00
Chris Beams
0320cc582b Introduce BeanFactoryAnnotationUtils
Commit 3f387eb9cf 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-9443
Backport-Issue: SPR-6847
Backport-Commit: a4b00c732b
2012-06-27 23:09:06 +02:00
Chris Beams
3f387eb9cf Refactor and deprecate TransactionAspectUtils
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.

Issue: SPR-9443
Backport-Issue: SPR-6847
Backport-Commit: 096693c46f
2012-06-27 23:06:05 +02:00
Spring Buildmaster
b32a365f14 Increment version to 3.1.2.BUILD-SNAPSHOT 2012-02-16 15:38:16 -08:00
Spring Buildmaster
79c9ca1a26 Release version 3.1.1.RELEASE 2012-02-16 15:33:27 -08:00
Chris Beams
e81df2ef3e Improve @Configuration bean name discovery
Prior to this commit, and based on earlier changes supporting SPR-9023,
ConfigurationClassBeanDefinitionReader employed a simplistic strategy
for extracting the 'value' attribute (if any) from @Configuration in
order to determine the bean name for imported and nested configuration
classes. An example case follows:

  @Configuration("myConfig")
  public class AppConfig { ... }

This approach is too simplistic however, given that it is possible in
'configuration lite' mode to specify a @Component-annotated class with
@Bean methods, e.g.

  @Component("myConfig")
  public class AppConfig {
      @Bean
      public Foo foo() { ... }
  }

In this case, it's the 'value' attribute of @Component, not
@Configuration, that should be consulted for the bean name. Or indeed if
it were any other stereotype annotation meta-annotated with @Component,
the value attribute should respected.

This kind of sophisticated discovery is exactly what
AnnotationBeanNameGenerator was designed to do, and
ConfigurationClassBeanDefinitionReader now uses it in favor of the
custom approach described above.

To enable this refactoring, nested and imported configuration classes
are no longer registered as GenericBeanDefinition, but rather as
AnnotatedGenericBeanDefinition given that AnnotationBeanNameGenerator
falls back to a generic strategy unless the bean definition in question
is assignable to AnnotatedBeanDefinition.

A new constructor accepting AnnotationMetadata
has been added to AnnotatedGenericBeanDefinition in order to support
the ASM-based approach in use by configuration class processing. Javadoc
has been updated for both AnnotatedGenericBeanDefinition and its now
very similar cousin ScannedGenericBeanDefinition to make clear the
semantics and intention of these two variants.

Issue: SPR-9023
2012-02-15 15:33:35 +01:00
Chris Beams
0a5392e37d Compensate for changes in JDK 7 Introspector
Prior to JDK 7, java.beans.Introspector registered indexed write methods
irrespective of return type, for example either of the following methods
were legal

    void setFoo(int i, Foo foo)
    Object setFoo(int i, Foo foo)

This was considered a bug and disallowed starting with JDK 7, such that
only the former signature is a candidate.

Supporting non-void returning setter methods is exactly what
ExtendedBeanInfo was designed to do, and prior to this commit, the
implementation of ExtendedBeanInfo assumed this (somewhat surprising)
behavior from the underlying Introspector, and because it worked out of
the box, took no extra steps to recognize and register these methods.
For this reason, non-void returning indexed write methods were not
registered under JDK 7+, causing test failures in ExtendedBeanInfoTests.

Now the implementation is careful to detect these methods without any
assumption about Introspector behavior, such that they are registered in
exactly the same fashion across JDK versions.

Issue: SPR-9014
2012-02-13 15:01:06 +01:00
Chris Beams
b787a68f20 Avoid 'type mismatch' errors in ExtendedBeanInfo
Prior to this commit, ExtendedBeanInfo would add non-indexed write
methods without consideration for the presence of indexed read/write
methods, which is invalid per the JavaBeans spec and per the behavior
of java.beans.Introspector.  That is, a method with the signature

    void setFoo(Foo foo)

Should never be registered as a write method if the following method
signature is also present in the class

    void setFoo(int i, Foo foo)

In most cases, this oversight caused no problems, but in certain
situations where a bean actually contains such a mismatch of methods,
"type mismatch" errors were thrown when ExtendedBeanInfo attempted the
illegal addition against the underlying property descriptor.

The implementation is now more careful about checking the parameter type
of write methods -- if the property descriptor in question is an
IndexedPropertyDescriptor, i.e. has an indexed write method, then any
non-indexed write method candidate must have a single *array* parameter,
which conforms to the spec and to Introspector behavior.

Issue: SPR-8937
2012-02-13 15:01:06 +01:00
Chris Beams
ef143d363e Polish ExtendedBeanInfo and tests
ExtendedBeanInfo

 - Reduce log messages from warn to debug

 - Remove now-incorrect comment indicating underlying property
   descriptors are never modified (they actually are as of SPR-8806)

ExtendedBeanInfoTests

 - Consolidate SPR-8949 tests

 - Eliminate compiler warnings

Issue: SPR-8949, SPR-8806
2012-02-13 15:01:05 +01:00
Chris Beams
f1ecd1ca2a Detect overridden boolean getters in ExtendedBeanInfo
Prior to this commit, and due to idiosyncracies of
java.beans.Introspector, overridden boolean getter methods were not
detected by Spring's ExtendedBeanInfo, which relied on too-strict
Method equality checks when selecting read and write methods.

Now ExtendedBeanInfo uses Spring's ClassUtils#getMostSpecificMethod
against the methods returned from java.beans.Introspector in order
to ensure that subsequent equality checks are reasonable to make.

Issue: SPR-8949
2012-02-09 22:23:57 +01:00
Chris Beams
c1df51a3b4 Polish ExtendedBeanInfoTests
Clean up ignored test, consolidate and document tests cornering
covariant return type edge cases.

Issue: SPR-8079, SPR-8806
2012-02-09 22:23:57 +01:00
Juergen Hoeller
4aa8b96687 write method parameter type preferred over read method parameter type for property conversion (fixing regression; SPR-8964) 2012-02-08 17:51:06 +01:00