Commit Graph

1122 Commits

Author SHA1 Message Date
Chris Beams c03a950706 Polish tests and Javadoc for SPR-8824
Issue: SPR-8824
2011-11-18 03:36:26 +00:00
Chris Beams 224cf11fcb Make @Configuration class enhancement idempotent
The registration of more than one ConfigurationClassPostProcessor
results in the double-enhancement of @Configuration classes, i.e. a
two-deep CGLIB subclass hierarchy is created.

As a side-effect of changes introduced in 3.1 M2 fixing SPR-8080, this
behavior now results in an infinite loop at CGLIB callback processing
time, leading to a StackOverflowException which is then suppressed by
the container, and ultimately results in the user being presented with
an unintuitive "Bean 'x' is not already in creation" exception.

This fix introduces a marker interface 'EnhancedConfiguration' to be
implemented by all generated @Configuration subclasses. The
configuration class enhancer can then behave in an idempotent fashion
by checking to see whether a candidate @Configuration class is already
assignable to this type i.e. already enhanced and ignore it if so.

Naturally, users should avoid registering more than one
ConfigurationClassPostProcessor, but this is not always possible. As
with the case in point, SPR-8824 originates from problems with
spring-data-neo4j, which explicitly registers its own
ConfigurationClassPostProcessor. The user has little control over this
arrangement, so it is important that the framework is defensive as
described above.

Issue: SPR-8824
2011-11-18 03:25:16 +00:00
Chris Beams 70c28a0bc5 Add Apache license header where missing in src/main 2011-11-16 18:23:56 +00:00
Chris Beams 9c0c87f6a7 Polish AutoProxyRegistrar 2011-11-16 18:23:45 +00:00
Chris Beams d1f6672a58 Refactor ImportSelector support
Separate concerns of @Configuration class selection from the need to
register certain infrastructure beans such as auto proxy creators.

Prior to this change, ImportSelector implementations were responsible
for both of these concerns, leading to awkwardness and duplication.

Also introduced in this change is ImportBeanDefinitionRegistrar and
two implementations, AutoProxyRegistrar and AspectJAutoProxyRegistrar.
See the refactored implementations of CachingConfigurationSelector,
TransactionManagementConfigurationSelector to see the former;
AspectJAutoProxyConfigurationSelector to see the latter.

ImportSelector and ImportBeanDefinitionRegistrar are both handled as
special-case arguments to the @Import annotation within
ConfigurationClassParser.

These refactorings are important because they ensure that Spring users
will be able to understand and extend existing @Enable* annotations
and their backing ImportSelector and @Configuration classes, as well
as create their own with a minimum of effort.
2011-11-16 04:21:28 +00:00
Chris Beams 4f3cbb45f4 Introduce @EnableCaching
See EnableCaching Javadoc for details.

Issue: SPR-8312
2011-11-16 04:21:21 +00:00
Chris Beams 732bf58570 Rename @CacheDefinitions => @Caching
Also eliminate all 'cache definition' language in favor of
'cache operation' in comments, method and parameter names (most
classes had already been refactored to this effect).
2011-11-16 04:21:12 +00:00
Chris Beams a252a285e2 Convert cache package line endings from CRLF => LF
Unfortunately creates a large diff due to whitespace changes as well as
false attribution of authorship from a git/svn 'blame' perspective.

Be sure to perform diffs using `git diff -w` or `svn diff -w` when
reviewing recent changes to these sources to ignore all whitespace.
2011-11-16 04:21:06 +00:00
Chris Beams f9879b762b Rename KeyGenerator#extract => #generate 2011-11-16 04:20:57 +00:00
Chris Beams 06306f9149 Extract various constants in DefaultKeyGenerator 2011-11-16 04:20:53 +00:00
Chris Beams 83d099db98 Prune CacheAspectSupport#setCacheOperationSource
In favor of existing #setCacheOperationSources(CacheOperationSource...)

Also polish Javadoc throughout, replacing stale references to
CacheDefinitionSource where appropriate as well as other minor changes
2011-11-16 04:20:50 +00:00
Chris Beams 42cbee883f Add generics to AbstractCacheManager#caches
Facilitates type-safe programmatic configuration from @Bean methods:

    @Bean
    public CacheManager cacheManager() {
        SimpleCacheManager cm = new SimpleCacheManager();
        cm.setCaches(Arrays.asList(
            new ConcurrentMapCache("default"),
            new ConcurrentMapCache("primary"),
            new ConcurrentMapCache("secondary")
        ));
        return cm;
    }

Prior to this change, the code above would have raised errors on the
Arrays.asList() call because it returns a Collection<? extends Cache>
as opposed to Collection<Cache>.

After this change, AbstractCacheManager expects
Collection<? extends Cache> throughout.
2011-11-16 04:20:46 +00:00
Chris Beams 96200b690c Refactor cache support test hierarchy
Refactored getConfig => getApplicationContext such that subclasses have
control over the type of ApplicationContext used by the base class
tests. Done in anticipation of @EnableCaching tests that will favor use
of AnnotationConfigApplicationContext

Also updated all use of ClassPathXmlApplictionContext to
GenericXmlApplicationContext, which is generally preferred.
2011-11-16 04:20:39 +00:00
Chris Beams 8abb315042 Fix cache generics warnings; polish whitespace 2011-11-16 04:20:32 +00:00
Chris Beams 1533822b0a Update proxyTargetClass-related Javadoc; add tests
There was some question about whether enabling subclass proxies via
proxyTargetClass / proxy-target-class settings would break annotation-
based demarcation of joinpoints due to inability to discover those
annotations in various scenarios. The provided tests prove that in
any conceivable case, these annotations (@Transactional, at least)
are discovered in a consistent fashion, meaning that switching proxy
strategies should be transparent to the application and honor
intended annotation semantics.
2011-11-16 04:20:28 +00:00
Chris Beams 124662189e Polish @EnableAsync imports, etc 2011-11-16 04:20:22 +00:00
Chris Beams 43b3b4c261 Polish @Enable* Javadoc 2011-11-16 04:20:17 +00:00
Chris Beams 40798bd48f Improve ImportStack#toString output 2011-11-16 04:20:12 +00:00
Chris Beams 4ededaf11c Fix typo in DateTimeFormat Javadoc
Issue: SPR-8838
2011-11-13 01:38:44 +00:00
Chris Beams b167b75453 Polish @Scheduled Javadoc
Add reference to @EnableScheduling and <task:annotation-driven>
2011-11-13 01:38:40 +00:00
Costin Leau dc88a7c8ba SPR-8830
SPR-8082
SPR-7833
+ add support for CacheDefinitions declarations inside XML
+ more integration tests
2011-11-09 17:53:51 +00:00
Costin Leau e4c88553d8 + rename test (as otherwise it gets picked even if it's abstract) 2011-11-09 10:52:22 +00:00
Costin Leau 473eaac117 + temporarily disable XML defs (since cache-update and cache-definition are not yet supported) 2011-11-09 10:44:14 +00:00
Costin Leau eddb0ac3be + introduced @CacheUpdate annotation
+ introduced @CacheDefinition annotation
+ introduced meta-annotation to allow multiple @Cache annotations
SPR-7833
SPR-8082
2011-11-09 10:00:44 +00:00
Juergen Hoeller 3bd9a3e3e0 RmiClientInterceptor detects nested SocketException as connect failure as well (SPR-8628) 2011-10-20 11:09:14 +00:00
Juergen Hoeller 2fdc2b5822 fixed StandardServlet/PortletEnvironment to check for JNDI (for Google App Engine compatibility) 2011-10-20 10:46:16 +00:00
Juergen Hoeller de5a007e46 cleanup of conversation dependencies 2011-10-20 09:56:07 +00:00
Chris Beams 38e90105a0 Support destroy method inference
Anywhere the value of a destroy method may be expressed, specifying
the value "(inferred)" now indicates that the container should attempt
to automatically discover a destroy method. This functionality is
currently limited to detecting public, no-arg methods named 'close';
this is particularly useful for commonly used types such as Hibernate
SessionFactory most JDBC DataSource implementations, JMS connection
factories, and so forth.

This special value is captured as the constant
AbstractBeanDefinition#INFER_METHOD, which in turn serves as the default
value of the @Bean#destroyMethod attribute.

For example in the following case

    @Bean
    public BasicDataSource dataSource() { ... }

the container will automatically detect BasicDataSource#close and invoke
it when the enclosing ApplicationContext is closed. This is exactly
equivalent to

    @Bean(destroyMethod="(inferred)")
    public BasicDataSource dataSource() { ... }

A user may override this inference-by-default convention simply by
specifying a different method

    @Bean(destroyMethod="myClose")
    public MyBasicDataSource dataSource() { ... }

or, in the case of a bean that has an otherwise inferrable 'close'
method, but the user wishes to disable handling it entirely, an empty
string may be specified

    @Bean(destroyMethod="")
    public MyBasicDataSource dataSource() { ... }

The special destroy method name "(inferred)" may also be specified in
an XML context, e.g.

    <bean destroy-method="(inferred)">
        or
    <beans default-destroy-method="(inferred)">

Note that "(inferred)" is the default value for @Bean#destroyMethod,
but NOT for the destroy-method and default-destroy-method attributes
in the spring-beans XML schema.

The principal reason for introducing this feature is to avoid forcing
@Configuration class users to type destroyMethod="close" every time a
closeable bean is configured. This kind of boilerplate is easily
forgotten, and this simple convention means the right thing is done
by default, while allowing the user full control over customization or
disablement in special cases.

Issue: SPR-8751
2011-10-12 02:09:04 +00:00
Chris Beams 739775ca19 Introduce @EnableAspectJAutoProxy
Issue: SPR-8138
2011-10-11 18:51:41 +00:00
Chris Beams 3920c5a158 Polish @ComponentScan/@Configuration/@Lazy Javadoc 2011-10-11 18:51:15 +00:00
Juergen Hoeller 0d02ef5fe5 removed conversation prototype from 3.1 codebase 2011-10-11 16:22:15 +00:00
Chris Beams 2760542182 Add repro test case for package-private @Bean issue
Reproduces the issue described in SPR-8756 in addition to demonstrating
the suggested workaround.

Issue: SPR-8756, SPR-8725
2011-10-11 04:02:03 +00:00
Chris Beams 980c15d578 Distinguish between different bridge method types
Add BridgeMethodResolver#isJava6VisibilityBridgeMethodPair to
distinguish between (a) bridge methods introduced in Java 6 to
compensate for inheriting public methods from non-public superclasses
and (b) bridge methods that have existed since Java 5 to accommodate
return type covariance and generic parameters.

In the former case, annotations should be looked up from the original
bridged method (SPR-7900).  In the latter, the annotation should be
looked up against the bridge method itself (SPR-8660).

As noted in the Javadoc for the new method, see
http://stas-blogspot.blogspot.com/2010/03/java-bridge-methods-explained.html
for a useful description of the various types of bridge methods, as
well as http://bugs.sun.com/view_bug.do?bug_id=6342411, the bug fixed in
Java 6 resulting in the introduction of 'visibility bridge methods'.

Issue: SPR-8660, SPR-7900
2011-10-10 05:40:21 +00:00
Chris Beams 6837111bda Refactor AnnotationUtils#findAllAnnotationAttributes
Remove all convenience variants of #findAllAnnotationAttributes and
refactor the remaining method to accept a MetadataReaderFactory
instead of creating its own SimpleMetadataReaderFactory internally.
This allows clients to use non-default class loaders as well as
customize the particular MetadataReaderFactory to be used (e.g.
'simple' vs 'caching', etc).

Issue: SPR-8752
2011-10-09 20:32:21 +00:00
Chris Beams d122ecb42e Move AdviceMode from .config to .annotation package 2011-10-09 07:55:08 +00:00
Chris Beams 1819bee35f Revert deprecation of AbstractSingletonPFB and co
Removed formal deprecation warnings for AbstractSingletonFactoryBean and
its TransactionProxyFactoryBean and CacheProxyFactoryBean subclasses.

This is principally because TPFB is still used by Grails and could
conceivably be used to good effect by any third-party framework in a
similar fashion. CPFB is new with 3.1, but similar use is predictable.

Deprecations have been replaced by strong recommendations that users
avoid these types in modern Spring applications and favor the use of
namespaces and annotatinos, such as tx: and @Transactional (around
since Spring 2.x) and cache: and @Cacheable.

Issue: SPR-8680, SPR-8686
2011-10-09 07:54:54 +00:00
Chris Beams 870d903417 Add INFER_METHOD constant and update @Bean Javadoc
In anticipation of 'destroy method inference' feature, introduce
ConfigurationClassUtils#INFER_METHOD and update @Bean#destroyMethod to
reflect its use.

Issue: SPR-8751
2011-10-09 07:54:39 +00:00
Chris Beams 6b4ef0237c Add code examples to and polish @Bean Javadoc 2011-10-09 07:54:33 +00:00
Costin Leau 40d88fd991 SPR-8730
+ more tests
2011-10-07 20:16:58 +00:00
Costin Leau a12ebbfded SPR-8730
+ expose key-generator in the XML namespace
2011-10-07 19:45:05 +00:00
Sam Brannen aa7a100807 [SPR-8178] re-enabled testPrintNull(). 2011-09-26 18:59:11 +00:00
Rossen Stoyanchev 3d50d416eb SPR-8718 Revert fix from earlier for now (need a different approach). 2011-09-26 17:58:49 +00:00
Sam Brannen 5309e43ea0 [SPR-8178] @Ignore-ing testPrintNull() until it is determined why changes to GenericConversionService broke this test. 2011-09-26 17:39:04 +00:00
Sam Brannen 052d3e7ccb [SPR-8718] now using correct JIRA ID in the comments. 2011-09-26 16:28:34 +00:00
Sam Brannen f752b47fcb [SPR-8178] @Ignore-ing testDefaultNumberFormatting() until it is determined why changes to GenericConversionService broke this test. 2011-09-26 16:24:51 +00:00
Chris Beams 15a8f776b9 Clarify stereotype and exception translation Javadoc
Cite original inspiriation by Domain-Driven Design, but make clear the
flexible and general-purpose nature of Spring's stereotype annotations
such as @Repository and @Service.

Also update @Repository Javadoc with more explicit instructions about
switching on exception translation through use of
PersistenceExceptionTranslationPostProcessor, and update PETPP Javadoc
for style as well as concrete examples of 'resource factories' that
implement the PersistenceExceptionTranslator interface

Issue: SPR-8691
2011-09-13 17:53:15 +00:00
Keith Donald 1a2f96000e clarified repository definition from DDD and removed comparison with DAO to reduce confusion 2011-09-13 14:31:41 +00:00
Chris Beams 2e5f3559d3 Fix handling of @EnableLoadTimeWeaving AUTODETECT
Issue: SPR-8643
2011-09-03 22:37:16 +00:00
Costin Leau d9de19d7b3 SPR-8653
+ refactor a bit the internals of CacheAspect to allow invocations that do not throw any exceptions (AspectJ)
2011-09-02 15:37:42 +00:00
Sam Brannen 1de71c6e37 [SPR-8222] Upgraded to JUnit 4.9. 2011-08-30 13:16:12 +00:00