Go to file
Chris Beams d9f7fdd120 Support reading nested annotations via ASM
Background

  Spring 3.1 introduced the @ComponentScan annotation, which can accept
  an optional array of include and/or exclude @Filter annotations, e.g.

     @ComponentScan(
         basePackages = "com.acme.app",
         includeFilters = { @Filter(MyStereotype.class), ... }
     )
     @Configuration
     public class AppConfig { ... }

  @ComponentScan and other annotations related to @Configuration class
  processing such as @Import, @ImportResource and the @Enable*
  annotations are parsed using reflection in certain code paths, e.g.
  when registered directly against AnnotationConfigApplicationContext,
  and via ASM in other code paths, e.g. when a @Configuration class is
  discovered via an XML bean definition or when included via the
  @Import annotation.

  The ASM-based approach is designed to avoid premature classloading of
  user types and is instrumental in providing tooling support (STS, etc).

  Prior to this commit, the ASM-based routines for reading annotation
  attributes were unable to recurse into nested annotations, such as in
  the @Filter example above. Prior to Spring 3.1 this was not a problem,
  because prior to @ComponentScan, there were no cases of nested
  annotations in the framework.

  This limitation manifested itself in cases where users encounter
  the ASM-based annotation parsing code paths AND declare
  @ComponentScan annotations with explicit nested @Filter annotations.
  In these cases, the 'includeFilters' and 'excludeFilters' attributes
  are simply empty where they should be populated, causing the framework
  to ignore the filter directives and provide incorrect results from
  component scanning.

  The purpose of this change then, is to introduce the capability on the
  ASM side to recurse into nested annotations and annotation arrays. The
  challenge in doing so is that the nested annotations themselves cannot
  be realized as annotation instances, so must be represented as a
  nested Map (or, as described below, the new AnnotationAttributes type).

  Furthermore, the reflection-based annotation parsing must also be
  updated to treat nested annotations in a similar fashion; even though
  the reflection-based approach has no problem accessing nested
  annotations (it just works out of the box), for substitutability
  against the AnnotationMetadata SPI, both ASM- and reflection-based
  implementations should return the same results in any case. Therefore,
  the reflection-based StandardAnnotationMetadata has also been updated
  with an optional 'nestedAnnotationsAsMap' constructor argument that is
  false by default to preserve compatibility in the rare case that
  StandardAnnotationMetadata is being used outside the core framework.
  Within the framework, all uses of StandardAnnotationMetadata have been
  updated to set this new flag to true, meaning that nested annotation
  results will be consistent regardless the parsing approach used.

  Spr9031Tests corners this bug and demonstrates that nested @Filter
  annotations can be parsed and read in both the ASM- and
  reflection-based paths.

Major changes

 - AnnotationAttributes has been introduced as a concrete
   LinkedHashMap<String, Object> to be used anywhere annotation
   attributes are accessed, providing error reporting on attribute
   lookup and convenient type-safe access to common annotation types
   such as String, String[], boolean, int, and nested annotation and
   annotation arrays, with the latter two also returned as
   AnnotationAttributes instances.

 - AnnotationUtils#getAnnotationAttributes methods now return
   AnnotationAttributes instances, even though for binary compatibility
   the signatures of these methods have been preserved as returning
   Map<String, Object>.

 - AnnotationAttributes#forMap provides a convenient mechanism for
   adapting any Map<String, Object> into an AnnotationAttributes
   instance. In the case that the Map is already actually of
   type AnnotationAttributes, it is simply casted and returned.
   Otherwise, the map is supplied to the AnnotationAttributes(Map)
   constructor and wrapped in common collections style.

 - The protected MetadataUtils#attributesFor(Metadata, Class) provides
   further convenience in the many locations throughout the
   .context.annotation packagage that depend on annotation attribute
   introspection.

 - ASM-based core.type.classreading package reworked

   Specifically, AnnotationAttributesReadingVisitor has been enhanced to
   support recursive reading of annotations and annotation arrays, for
   example in @ComponentScan's nested array of @Filter annotations,
   ensuring that nested AnnotationAttributes objects are populated as
   described above.

   AnnotationAttributesReadingVisitor has also been refactored for
   clarity, being broken up into several additional ASM
   AnnotationVisitor implementations. Given that all types are
   package-private here, these changes represent no risk to binary
   compatibility.

 - Reflection-based StandardAnnotationMetadata updated

   As described above, the 'nestedAnnotationsAsMap' constructor argument
   has been added, and all framework-internal uses of this class have
   been updated to set this flag to true.

Issue: SPR-7979, SPR-8719, SPR-9031
2012-02-07 21:57:49 +01:00
build-spring-framework LocalContainerEntityManagerFactoryBean etc 2012-02-07 21:00:14 +01:00
org.springframework.aop Add <license> section to 3.1.x Maven poms 2012-01-31 15:18:05 +01:00
org.springframework.asm Add <license> section to 3.1.x Maven poms 2012-01-31 15:18:05 +01:00
org.springframework.aspects Relax -aspects dependence on -test (compile=>test) 2012-02-04 17:49:11 +01:00
org.springframework.beans Support reading nested annotations via ASM 2012-02-07 21:57:49 +01:00
org.springframework.context Support reading nested annotations via ASM 2012-02-07 21:57:49 +01:00
org.springframework.context.support added "durability" and "description" properties to JobDetailFactoryBean (SPR-9080) 2012-02-07 15:54:18 +01:00
org.springframework.core Support reading nested annotations via ASM 2012-02-07 21:57:49 +01:00
org.springframework.expression Merge pull request #21 from aclement/spr9038 2012-02-01 22:47:36 +01:00
org.springframework.instrument Add <license> section to 3.1.x Maven poms 2012-01-31 15:18:05 +01:00
org.springframework.instrument.tomcat Add <license> section to 3.1.x Maven poms 2012-01-31 15:18:05 +01:00
org.springframework.integration-tests Add <license> section to 3.1.x Maven poms 2012-01-31 15:18:05 +01:00
org.springframework.jdbc Fix single quote parsing in NamedParameterUtils 2012-02-06 09:47:17 +01:00
org.springframework.jms Add <license> section to 3.1.x Maven poms 2012-01-31 15:18:05 +01:00
org.springframework.orm LocalContainerEntityManagerFactoryBean's "persistenceUnitName" applies to "packagesToScan" as well; DefaultPersistenceUnitManager uses containing jar as persistence unit root URL for default unit (SPR-8832) 2012-02-07 20:59:48 +01:00
org.springframework.oxm Add <license> section to 3.1.x Maven poms 2012-01-31 15:18:05 +01:00
org.springframework.spring-library Add <license> section to 3.1.x Maven poms 2012-01-31 15:18:05 +01:00
org.springframework.spring-parent Add <license> section to 3.1.x Maven poms 2012-01-31 15:18:05 +01:00
org.springframework.test Add <license> section to 3.1.x Maven poms 2012-01-31 15:18:05 +01:00
org.springframework.transaction Add <license> section to 3.1.x Maven poms 2012-01-31 15:18:05 +01:00
org.springframework.web Servlet/PortletContextResource's "isReadable()" implementation returns false for directories (SPR-9067) 2012-02-07 15:54:16 +01:00
org.springframework.web.portlet Servlet/PortletContextResource's "isReadable()" implementation returns false for directories (SPR-9067) 2012-02-07 15:54:16 +01:00
org.springframework.web.servlet Tighten FlashMapManager for use with alternative storage options 2012-02-06 18:04:27 -05:00
org.springframework.web.struts Add <license> section to 3.1.x Maven poms 2012-01-31 15:18:05 +01:00
spring-build Add spring-build 2.5.2 2011-12-16 11:56:51 +01:00
spring-framework-reference SPR-9085 Correct typo. 2012-02-02 09:56:02 -05:00
.gitignore Ignore Gradle-related files and directories 2012-01-31 15:18:05 +01:00
README.md Update links to reference and api documentation 2012-01-16 22:16:43 +01:00
build.properties Increment version to 3.1.1.BUILD-SNAPSHOT 2011-12-16 11:59:06 +01:00
build.versions Convert CRLF (dos) to LF (unix) 2011-12-21 14:52:47 +01:00
ci-build.properties adding properties file to simplify ant use in Bamboo CI build 2008-12-17 15:47:14 +00:00
eclipse-code-formatter.xml h2 embedded db support; updated formatting conventions not to auto-format javadoc; added hsqldb and h2 to jdbc maven pom as optional deps 2009-05-09 22:27:05 +00:00
spring-framework.ipr Updated IntelliJ project for JUnit 4.9.0 2012-02-07 15:41:49 +01:00
spring-framework.psf Renamed org.springframework.instrument.classloading module to org.springframework.instrument.tomcat 2009-09-25 12:51:58 +00:00

README.md

Spring Framework

The Spring Framework provides a comprehensive programming and configuration model for modern Java-based enterprise applications - on any kind of deployment platform. A key element of Spring is infrastructural support at the application level: Spring focuses on the "plumbing" of enterprise applications so that teams can focus on application-level business logic, without unnecessary ties to specific deployment environments.

The framework also serves as the foundation for Spring Integration, Spring Batch and the rest of the Spring family of projects. Browse the repositories under the SpringSource organization on GitHub for a full list.

.NET and Python variants are available as well.

Downloading artifacts

Instructions on downloading Spring artifacts via Maven and other build systems are available via the project wiki.

Documentation

See the current Javadoc and Reference docs.

Getting support

Check out the Spring forums and the Spring tag on StackOverflow. Commercial support is available too.

Issue Tracking

Spring's JIRA issue tracker can be found here. Think you've found a bug? Please consider submitting a reproduction project via the spring-framework-issues repository. The readme provides simple step-by-step instructions.

Building from source

Instructions on building Spring from source are available via the project wiki.

Contributing

Pull requests are welcome; you'll be asked to sign our contributor license agreement (CLA). Trivial changes like typo fixes are especially appreciated (just fork and edit!). For larger changes, please search through JIRA for similiar issues, creating a new one if necessary, and discuss your ideas with the Spring team.

Staying in touch

Follow @springframework and its team members on Twitter. In-depth articles can be found at the SpringSource team blog, and releases are announced via our news feed.

License

The Spring Framework is released under version 2.0 of the Apache License.