Spring 2.5 RC1 is here - introducing new configuration approaches

As some of you will have noticed already, Spring 2.5 RC1 has finally been released on Monday and is waiting for you to give it a test drive! Spring 2.5 is in many ways the release that completes Spring 2.0's mission: providing the most flexible and most comprehensive configuration model for both Java 1.4 and Java 5. Spring 2.5 focuses on particularly comprehensive support for Java 5, introducing various further annotations options. I'd like to take the opportunity to point out the unifying themes behind this release:
Spring 2.5 allows for convenient externalized configuration while also keeping it as concise as possible. This is building on Spring 2.0's support for XML schema namespaces, with Spring 2.5 introducing new "context" and "jms" configuration namespaces. The latter is a particularly good example for the value-add that a Spring configuration namespace can provide - definitely worth adopting if you're using Spring 2.0 style message-driven objects! Additionally, Spring allows for programmatic bootstrap with no XML involved as well (if desired); we made sure to provide all of Spring 2.5's goodies for that style of bootstrapping as well.
As a core theme, Spring 2.5 provides comprehensive support for configuration annotations in application components. This is following up on what Spring 2.0 started with @Required, @Transactional, @ManagedResource for JMX and JPA's @PersistenceContext / @PersistenceUnit. Spring 2.5 supports JSR 250's @PostConstruct (for init methods), @PreDestroy (for destroy methods) and @Resource (for injection of named managed objects) as well as JAX-WS 2.0's @WebServiceRef (for injection of web service client views) and @EJB (for injection of session bean client views). Furthermore, Spring 2.5 provides the one configuration annotation that rules them all: @Autowired (for type-driven autowiring, optionally in conjunction with qualifier annotations that choose a specific object from a set of matching candidates).
Spring 2.5 goes even further for web controllers: The newly introduced @RequestMapping, @RequestParam and @ModelAttribute annotations allow for writing annotated web MVC controllers without implementing specific interfaces or deriving from specific base classes, purely based on annotations for mapping to specific request paths. This is essentially a next generation of the good old MultiActionController approach, capable of handling forms in a very flexible fashion as well. Of course, as first-class Spring-managed objects, such controllers may use the core lifecycle and injection annotations mentioned above, for example @Autowired… The revised PetClinic sample application in Spring 2.5 shows those facilities in use, with all of PetClinic's web controllers implemented in annotation style now. Check it out!
Spring 2.5 also introduces the new annotation-based TestContext framework for integration tests, supporting JUnit 3.8, JUnit 4.4 and TestNG. This is a compelling alternative to Spring 2.0's base classes for JUnit 3.8, supporting Spring 2.5's core configuration annotations (such as @Autowired) for test classes and providing flexible test context configuration through annotations. This is powerful, flexible and loosely coupled: Spring-style context management applied to the world of integration testing.
As the most advanced level of annotation usage, Spring 2.5 allows for autodetecting annotated components in the classpath, using stereotype annotations such as @Repository, @Service, @Controller or the generic @Component. This allows you to avoid explicit XML bean definitions completely, with annotated components in specified packages registered implicitly. This can be adopted for specific purposes, for example autodetecting controllers in the web layer while service layer components are still defined explicitly.
Note that Spring 2.5 supports the same configuration annotations for any kind of managed component: Spring-defined DAOs, service beans, web controllers; components detected through scanning the classpath; @Configurable objects configured by the AspectJ configurer aspect; test classes run by the test context framework. All of those components may, for example, use @Autowired for injection purposes, with consistent semantics across all those different component types.
With all of that said, note that Spring 2.5 of course still supports the 'classic' Spring configuration approach as a first class citizen. Configuration annotations are an option which can be adopted at different levels: from configuration 'hints' in component classes, complementing XML bean definitions, up to self-sufficient components which express their entire configuration through annotations. Or of course no annotations at all: a perfectly viable way if you prefer the architectural benefits of externalized configuration, as well as obviously the primary option on Java 1.4.
Donal says:
Added on October 24th, 2007 at 8:10 pmApproximately, when is 2.5 expected to be released?
andre del bene says:
Added on October 25th, 2007 at 2:28 amAnd in the meantime Spring reached 2 million downloads on sourceforge!
Congratulations!
Solomon says:
Added on October 25th, 2007 at 8:59 amI'm pretty excited about all of these changes. Congrats on adding new value add configuration capabilities and performance enhancements.
I would like to request additions to the spring build process. It would be fantastic to have more source beyond spring-src.jar, for example spring-webmvc-src.jar and spring-testcases-src jar. The source code and better yet — the test cases, illuminate product usage much more than documentation… even with the fantastic documentation provided with the spring distribution.
On a different note, I see that @Controller was added, but the classic mvc controller was removed… Interesting decision.
Thomas Olsson says:
Added on October 25th, 2007 at 12:57 pmWhat dose the @Service tag do? Can't find anything on it in the ref doc.
Best Regards
Thomas
Mark Fisher (blog author) says:
Added on October 25th, 2007 at 2:26 pm[quote comment="57608"]It would be fantastic to have more source beyond spring-src.jar, for example spring-webmvc-src.jar and spring-testcases-src jar.[/quote]
Hello Solomon,
The distribution does include the complete set of individual source JARs per module; have a look in 'dist/module-sources'. For the test case sources, just look directly in the 'test' directory.
hope that helps
Mark
Solomon says:
Added on October 25th, 2007 at 8:27 pm@Mark, Thanks a lot. I guess I had a "doh!" moment.
The module-sources were right where you said they would be. However, It took me a while to find the tests… They're only on the gotta-download-the-world-of-dependencies download, not the other two versions.
Anyway, thanks again!
I was able to get a simple test running with Spring runtime with Guice's annotations. I'd say that the ease with which I did that is a great testament to the Spring Framework's well designed implementation.
Juergen Hoeller (blog author) says:
Added on October 28th, 2007 at 6:01 pmDonal, Spring 2.5 final is expected to be released in early November. We still need to close a couple of documentation gaps; otherwise, we're pretty close to final already.
Donal says:
Added on October 29th, 2007 at 10:38 am@Juergen, Thanks, I'm looking forward to the support for JUnit4
Prese Per Arrampicata says:
Added on November 4th, 2007 at 8:09 pmc, when is 2.5 expected?
Only approximately…
Prese
andre del bene says:
Added on November 5th, 2007 at 3:58 am@Prese Per Arrampicata (are you a climber
?)
probably you didn't read last Juergen's post: "Spring 2.5 final is expected to be released in early November"
Bye.
Vikas Kumar says:
Added on November 5th, 2007 at 4:01 pmDo you guys know any book coming out (with in detail feratures) for Spring 2.5?
Claude B. Diesse says:
Added on November 6th, 2007 at 7:48 pmVery pleased with the real focus on the java configuration and annotation support. I hope in Spring in the future will give priority to Java language development and not try to consider whole Java community as XML data programmers.
Also ask to Spring team to stop saying that the SpringFramework don't tie adopter to the Framework code ! It begin to hurt people, hearing that any time you write 3 lines about SpringFramework … How can you really evaluate dependence of millions of java coders out there ? Let anybody live with his choice and his filling about dependent or independent codes …
So said …, I will end by saying : good job for java configuration capabilities added to the product and the fact that anyone can choose to not use XML at all! I will give again a try to the 2.5 version with java 6.
Regards.
Claude
Brendan Johnston says:
Added on November 13th, 2007 at 6:26 pmI would appreciate an example of programmatic configuration.
Essentially a Spring version of the Guice guide (http://google-guice.googlecode.com/files/Guice 1.0 User's Guide.pdf).
Solomon says:
Added on November 14th, 2007 at 3:08 pm[quote comment="64662"]I would appreciate an example of programmatic configuration.
Essentially a Spring version of the Guice guide (http://google-guice.googlecode.com/files/Guice 1.0 User's Guide.pdf).[/quote]
I'm not sure what you mean by programmatic configuration exactly, whether you mean annotations in the Beans or an external configuration API.
Off hand, the following would be good places to understand Bean-based annotations in Spring
Download Spring 2.5 and look at PetClinic
Look at the spring User guide, specifically at the following section: http://static.springframework.org/spring/docs/2.5.x/reference/beans.html#beans-annotation-config
Those two together should answer most of your annotation questions.
If you're looking for an API solution, like Guice module/provider-like, the closest thing Spring has is hand-coding BeanDefinitions and BeanDefinitionBuilders. You can use those classes at your own peril.
You can also take a look at the JavaConfig project which is meant to be a programmatic API for Spring configuration. (http://www.springframework.org/javaconfig). Take a look here: http://blog.interface21.com/main/2007/11/04/spring-java-configuration-moving-ahead/
john wang says:
Added on September 8th, 2008 at 4:16 pm"With all of that said, note that Spring 2.5 of course still supports the 'classic' Spring configuration approach as a first class citizen. "
So does it mean the xml config will NOT override the annotation config, like some other framework does?