Commit Graph
472 Commits
Author SHA1 Message Date
Juergen Hoeller 5c7176b735 polishing
git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@4813 50f2f4bb-b051-0410-bef5-90022cba6387
2011-07-28 11:15:11 +00:00
Chris Beams ce0110bb28 Respect <description> within <entry> per beans XSD
Prior to this change, a parsing exception would be thrown if a
<description> element was placed within a <map><entry/></map>
element. The beans XSD has always permitted this arrangement,
but BeanDefinitionParserDelegate did not respect it. The latter now
simply ignores any <description> element, rather than failing.

Issue: SPR-8563

git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@4811 50f2f4bb-b051-0410-bef5-90022cba6387
2011-07-28 02:21:22 +00:00
Juergen Hoeller 16dd1b0a9e DefaultListableBeanFactory allows for init methods to register further bean definitions (again; SPR-7757)
git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@4809 50f2f4bb-b051-0410-bef5-90022cba6387
2011-07-27 22:51:26 +00:00
Juergen Hoeller eeb3d7f380 minor javadoc revision
git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@4725 50f2f4bb-b051-0410-bef5-90022cba6387
2011-07-18 21:50:15 +00:00
Chris Beams 7d9d255daf Determine FactoryBean object type via generics
For the particular use case detailed in SPR-8514, with this change we
now attempt to determine the object type of a FactoryBean through its
generic type parameter if possible.

For (a contrived) example:

@Configuration
public MyConfig {
    @Bean
    public FactoryBean<String> fb() {
        return new StringFactoryBean("foo");
    }
}

The implementation will now look at the <String> generic parameter
instead of attempting to instantiate the FactoryBean in order to call
its #getObjectType() method.

This is important in order to avoid the autowiring lifecycle issues
detailed in SPR-8514.  For example, prior to this change, the following
code would fail:

@Configuration
public MyConfig {
    @Autowired Foo foo;

    @Bean
    public FactoryBean<String> fb() {
        Assert.notNull(foo);
        return new StringFactoryBean("foo");
    }
}

The reason for this failure is that in order to perform autowiring,
the container must first determine the object type of all configured
FactoryBeans.  Clearly a chicken-and-egg issue, now fixed by this
change.

And lest this be thought of as an obscure bug, keep in mind the use case
of our own JPA support: in order to configure and return a
LocalContainerEntityManagerFactoryBean from a @Bean method, one will
need access to a DataSource, etc -- resources that are likely to
be @Autowired across @Configuration classes for modularity purposes.

Note that while the examples above feature methods with return
types dealing directly with the FactoryBean interface, of course
the implementation deals with subclasses/subinterfaces of FactoryBean
equally as well.  See ConfigurationWithFactoryBeanAndAutowiringTests
for complete examples.

There is at least a slight risk here, in that the signature of a
FactoryBean-returing @Bean method may advertise a generic type for the
FactoryBean less specific than the actual object returned (or than
advertised by #getObjectType for that matter). This could mean that an
autowiring target may be missed, that we end up with a kind of
autowiring 'false negative' where FactoryBeans are concerned. This is
probably a less common scenario than the need to work with an autowired
field within a FactoryBean-returning @Bean method, and also has a clear
workaround of making the generic return type more specific.

Issue: SPR-8514

git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@4681 50f2f4bb-b051-0410-bef5-90022cba6387
2011-07-06 09:15:37 +00:00
Juergen Hoeller 1ccdc8b717 switched from readResolve to readObject
git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@4665 50f2f4bb-b051-0410-bef5-90022cba6387
2011-07-04 21:21:33 +00:00
Juergen Hoeller 655754e421 optimized debug logging in case of non-convertible collection (SPR-8499)
git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@4663 50f2f4bb-b051-0410-bef5-90022cba6387
2011-07-04 09:43:08 +00:00
Juergen Hoeller 17a56fcfdd properly wrap IndexOutOfBoundsException even for List
git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@4655 50f2f4bb-b051-0410-bef5-90022cba6387
2011-07-03 20:24:12 +00:00
Juergen Hoeller 9be513d225 regular IndexOutOfBoundsException if index beyond auto-grow limit
git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@4654 50f2f4bb-b051-0410-bef5-90022cba6387
2011-07-03 20:12:18 +00:00
Juergen Hoeller 3cd0e47d45 restored original array behavior (no default growth of arrays)
git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@4653 50f2f4bb-b051-0410-bef5-90022cba6387
2011-07-03 20:05:07 +00:00
Juergen Hoeller a4e5318aff DataBinder uses a default limit of 256 for array/collection auto-growing (SPR-7842)
git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@4652 50f2f4bb-b051-0410-bef5-90022cba6387
2011-07-03 19:26:49 +00:00
Chris Beams f5be4b22bb Refactor BeanFactoryLocator to use getBean(Class)
Prior to this change, (Context)SingletonBeanFactoryLocator used
BeanFactoryUtils#beanOfType(ListableBeanFactory, Class) to locate the
bean of type BeanFactory.

The more modern approach is to use BeanFactory#getBean(Class), which
removes a dependency on ListableBeanFactory interface while at the same
time opening the implementation up to respecting autowiring exclusions,
primary metadata, etc.

Issue: SPR-8489

git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@4650 50f2f4bb-b051-0410-bef5-90022cba6387
2011-07-02 22:22:33 +00:00
Juergen Hoeller 2a7d7ad9c3 DefaultListableBeanFactory is only deserializable through a SerializedBeanFactoryReference
git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@4611 50f2f4bb-b051-0410-bef5-90022cba6387
2011-06-22 20:56:23 +00:00
Juergen Hoeller 6335538e35 getBean(name, type) attempts type conversion if necessary (SPR-8480)
git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@4607 50f2f4bb-b051-0410-bef5-90022cba6387
2011-06-22 20:52:28 +00:00
Chris Beams d058ba4579 Fix bridge method detection for class hierarchies
Prior to this change, @Autowired injection against an instance of a
subclass having different visibility than its superclass would fail
if the @Autowired method is declared only in the superclass. This is due
to an apparent change in the rules around bridge method generation
between Java 5 and Java 6, and possibly even varying across compiler
vendors.

Now, BridgeMethodResolver is used consistently when detecting
@Autowired, @Inject and @Resource metadata to bypass these bridge
methods if they exist.

Issue: SPR-7900

git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@4600 50f2f4bb-b051-0410-bef5-90022cba6387
2011-06-21 14:59:37 +00:00
Chris Beams b68f4d984a Provide default ParameterNameDiscoverer for AACBF
Prior to this change, AbstractAutowireCapableBeanFactory did not support
a default ParameterNameDiscoverer.  This meant that attempting to use
<constructor-arg name=".."> syntax would fail (with a fairly obscure
exception) as that feature depends on a ParameterNameDiscoverer to
introspect the constructor arguments.

This lack of a default was originally intended to avoid a dependency on
ASM, but now that (a) .asm is a built-in module and (b) .beans has a
non-optional compile-time dependency on .asm, there is no reason not to
provide this default.

The net effect is that in a number of locations throughout the
framework, namely in GenericApplicationContext and
AbstractRefreshableApplicationContext, it is no longer necessary to
explicitly call AACBF#setParameterNameDiscoverer. This also means that
using a naked BeanFactory (likely for testing scenarios) is that much
easier.

Issue: SPR-8184

git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@4568 50f2f4bb-b051-0410-bef5-90022cba6387
2011-06-17 09:47:19 +00:00
Chris Beams 6a7cb58fe3 Preserve shadowed fields in DirectFieldAccessor
Prior to this change, DirectFieldAccessor would ignore fields shadowed
in subclasses, favoring the last field processed, which happens to be
the most super declaration based on the way ReflectionUtils.doWithFields
works.

Because the locally shadowed field may be of a different type that the
superclass declaration, it is most correct to preserve and work with
the shadowed field.

Issue: SPR-8398

git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@4559 50f2f4bb-b051-0410-bef5-90022cba6387
2011-06-16 06:33:44 +00:00
Juergen Hoeller 8c0cfc859b restored support for String-to-ContextResource conversion (SPR-8383)
git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@4555 50f2f4bb-b051-0410-bef5-90022cba6387
2011-06-15 15:40:12 +00:00
Sam Brannen 5cde94dc4b Polishing Eclipse classpath settings
git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@4513 50f2f4bb-b051-0410-bef5-90022cba6387
2011-06-11 19:56:48 +00:00
Juergen Hoeller 03adc3b632 shortened build properties "org.junit.version" to "junit.version" and "org.testng.version" to "testng.version"; reverted SLF4J version back to 1.5.3 (for Hibernate 3.3.1 compatibility)
git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@4502 50f2f4bb-b051-0410-bef5-90022cba6387
2011-06-09 09:58:15 +00:00
Juergen Hoeller 80c86075f0 polishing
git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@4497 50f2f4bb-b051-0410-bef5-90022cba6387
2011-06-08 22:52:43 +00:00
Keith Donald b0a9781f0f restored TypeDescriptor getElementType, getMapKeyType, and getMapValueType compatibility; StringToCollection and Array Converters are now conditional and check targetElementType if present; TypeDesciptor#isAssignable no longer bothers with element type and map key/value types in checking assignability for consistency elsewhere; improved javadoc
git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@4478 50f2f4bb-b051-0410-bef5-90022cba6387
2011-06-07 02:51:44 +00:00
Keith Donald 0fcbb35889 null type descriptor handling
git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@4459 50f2f4bb-b051-0410-bef5-90022cba6387
2011-06-05 17:52:26 +00:00
Keith Donald eaa8a4271c improved null handling and javadoc
git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@4458 50f2f4bb-b051-0410-bef5-90022cba6387
2011-06-05 17:41:08 +00:00
Keith Donald c5425d0f43 broke out to top-level class for readability
git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@4456 50f2f4bb-b051-0410-bef5-90022cba6387
2011-06-05 08:37:08 +00:00
Keith Donald 89096b46b8 removed dependency on java.beans
git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@4455 50f2f4bb-b051-0410-bef5-90022cba6387
2011-06-05 08:29:14 +00:00
Keith Donald 4afc2c926d catch ConversionFailedException and fallback to default container conversion logic rather than propogate exception
git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@4453 50f2f4bb-b051-0410-bef5-90022cba6387
2011-06-05 06:04:49 +00:00
Keith Donald b58386da08 polishing
git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@4451 50f2f4bb-b051-0410-bef5-90022cba6387
2011-06-05 05:46:27 +00:00
Keith Donald a34147a53d revised TypeDescriptor NULL and element/mapKey/mapValue type semantics
git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@4450 50f2f4bb-b051-0410-bef5-90022cba6387
2011-06-05 04:43:18 +00:00
Chris Beams 976955f6ad Fix system environment tests on all platforms
Issue: SPR-8245

git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@4430 50f2f4bb-b051-0410-bef5-90022cba6387
2011-06-03 05:16:35 +00:00
Keith Donald c7cae10364 simplified TypeDescriptor usage and updated use of the API across BeanWrapper and SpEL; collapsed PropertyTypeDescriptor into TypeDescriptor for simplicity and ease of use; improved docs
git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@4424 50f2f4bb-b051-0410-bef5-90022cba6387
2011-06-02 23:37:19 +00:00
Sam Brannen f70fd0965d [SPR-8388] Cleared up confusing documentation regarding PropertyResolver and Environment.
git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@4403 50f2f4bb-b051-0410-bef5-90022cba6387
2011-06-01 21:05:23 +00:00
Sam Brannen d81b19e958 [SPR-8388] Improved documentation on default registered PropertyEditors; fixed typos and grammar in JavaDoc; suppressed warnings due to generics; etc.
git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@4402 50f2f4bb-b051-0410-bef5-90022cba6387
2011-06-01 20:54:48 +00:00
Chris Beams 55707983a1 Ignore failing tests on Windows
Attempt to access and modify the system environment works on OS X /
Linux but not under Windows. Does not represent any real failure for
production code - the need to modify the system environment is a
testing concern only, and one we can probably live without, considering
the losing battle necessary to make such a hack cross-platform.

Issue: SPR-8245

git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@4392 50f2f4bb-b051-0410-bef5-90022cba6387
2011-05-31 10:58:24 +00:00
Juergen Hoeller 766b189fd0 CustomNumberEditor generically declares numberClass as subclass of Number (matching NumberUtils)
git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@4372 50f2f4bb-b051-0410-bef5-90022cba6387
2011-05-29 20:55:15 +00:00
Juergen Hoeller 326c5f4b9b polishing
git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@4371 50f2f4bb-b051-0410-bef5-90022cba6387
2011-05-29 20:53:34 +00:00
Chris Beams cf19ecc5a7 Rename {Default=>Standard}Environment
Issue: SPR-8348

git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@4337 50f2f4bb-b051-0410-bef5-90022cba6387
2011-05-20 03:53:37 +00:00
Chris Beams ebea9ec66c 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

git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@4334 50f2f4bb-b051-0410-bef5-90022cba6387
2011-05-20 03:49:15 +00:00
Chris Beams 31bc941b28 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

git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@4300 50f2f4bb-b051-0410-bef5-90022cba6387
2011-05-13 03:41:29 +00:00
Chris Beams 26a0e223a4 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

git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@4296 50f2f4bb-b051-0410-bef5-90022cba6387
2011-05-12 12:28:13 +00:00
Chris Beams a091eb1c86 Introduce ReflectionUtils#getUniqueDeclaredMethods
This change is in support of certain polymorphism cases in
@Configuration class inheritance hierarchies.  Consider the following
scenario:

@Configuration
public abstract class AbstractConfig {
    public abstract Object bean();
}

@Configuration
public class ConcreteConfig {
    @Override
    @Bean
    public BeanPostProcessor bean() { ... }
}

ConcreteConfig overrides AbstractConfig's #bean() method with a
covariant return type, in this case returning an object of type
BeanPostProcessor.  It is critically important that the container
is able to detect the return type of ConcreteConfig#bean() in order
to instantiate the BPP at the right point in the lifecycle.

Prior to this change, the container could not do this.
AbstractAutowireCapableBeanFactory#getTypeForFactoryMethod called
ReflectionUtils#getAllDeclaredMethods, which returned Method objects
for both the Object and BeanPostProcessor signatures of the #bean()
method.  This confused the implementation sufficiently as not to
choose a type for the factory method at all.  This means that the
BPP never gets detected as a BPP.

The new method being introduced here, #getUniqueDeclaredMethods, takes
covariant return types into account, and filters out duplicates,
favoring the most specific / narrow return type.

Additionally, it filters out any CGLIB 'rewritten' methods, which
is important in the case of @Configuration classes, which are
enhanced by CGLIB.  See the implementation for further details.

git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@4262 50f2f4bb-b051-0410-bef5-90022cba6387
2011-05-06 19:07:25 +00:00
Chris Beams c892028705 Remove "Feature" support introduced in 3.1 M1
Feature-related support such as @Feature, @FeatureConfiguration,
and FeatureSpecification types will be replaced by framework-provided
@Configuration classes and convenience annotations such as
@ComponentScan (already exists), @EnableAsync, @EnableScheduling,
@EnableTransactionManagement and others.

Issue: SPR-8012,SPR-8034,SPR-8039,SPR-8188,SPR-8206,SPR-8223,
SPR-8225,SPR-8226,SPR-8227

git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@4255 50f2f4bb-b051-0410-bef5-90022cba6387
2011-05-06 19:03:52 +00:00
Chris Beams 84ace01244 Revert deprecation of BDRU#registerWithGeneratedName
The overloading necessary to preserve the new signature as well as
the old causes ambiguities leading to deprecation warnings in some
caller scenarios.

git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@4253 50f2f4bb-b051-0410-bef5-90022cba6387
2011-05-06 19:01:35 +00:00
Chris Beams e8d1df5037 Fix generics and serialization warnings
git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@4249 50f2f4bb-b051-0410-bef5-90022cba6387
2011-05-06 19:00:14 +00:00
Sam Brannen 0613ced0b2 polishing
git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@4244 50f2f4bb-b051-0410-bef5-90022cba6387
2011-05-06 15:35:40 +00:00
Micha Kiener ab4a3568b1 SPR-6416, initial commit for the conversation management
git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@4217 50f2f4bb-b051-0410-bef5-90022cba6387
2011-04-12 13:21:18 +00:00
Chris Beams 8dedf111bc Ignore non-prop 'set' methods in ExtendedBeanInfo
Previously, ExtendedBeanInfo would attempt to process methods named
exactly 'set'.  JavaBeans properties must have at least one character
following the 'set' prefix in order to qualify, and this is now
respected by EBI.

Thanks to Rob Winch for the patch fixing this problem.

Issue: SPR-8175

git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@4178 50f2f4bb-b051-0410-bef5-90022cba6387
2011-04-05 03:45:38 +00:00
Chris Beams 1271acb8eb Introduce ExtendedBeanInfo
Decorator for instances returned from
Introspector#getBeanInfo(Class<?>) that supports detection and inclusion
of non-void returning setter methods. Fully supports indexed properties
and otherwise faithfully mimics the default
BeanInfo#getPropertyDescriptors() behavior, e.g., PropertyDescriptor
ordering, etc.

This decorator has been integrated with CachedIntrospectionResults
meaning that, in simple terms, the Spring container now supports
injection of setter methods having any return type.

Issue: SPR-8079

git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@4144 50f2f4bb-b051-0410-bef5-90022cba6387
2011-03-31 12:06:36 +00:00
Agim Emruli e633c97bff fixed compile error in test with javac compiler
git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@4110 50f2f4bb-b051-0410-bef5-90022cba6387
2011-03-24 11:06:32 +00:00
Chris Beams d1c5bb0160 Eliminate warnings in .validation package
Issue: SPR-8062

git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@4103 50f2f4bb-b051-0410-bef5-90022cba6387
2011-03-18 06:47:12 +00:00