Bindings, Platforms, and Innovation
This presentation focuses on the Internet and separating myth from fact, history from the future, and the mundane from the imaginative. Bob Frankston presents a vision of what could and should be.
Tracking change and innovation in the enterprise software development community
Posted by Geoffrey Wiseman on Nov 19, 2007 06:30 PM
November 19th 2007 was a big day for the Spring Framework. Spring 2.5 was released, Interface21 has become SpringSource and InfoQ has published the first article in a series of articles by Mark Fisher of SpringSource on the new features: What's New in Spring 2.5: Part 1: Annotation-Based Configuration.
Describing the series of articles, Mark Fisher wrote:
The newly released Spring 2.5 continues this trend by offering further simplifications and powerful new features especially for those who are using Java 5 or greater. These features include annotation-driven dependency injection, auto-detection of Spring components on the classpath using annotations rather than XML for metadata, annotation support for lifecycle methods, a new web controller model for mapping requests to annotated methods, support for Junit 4 in the test framework, new additions to the Spring XML namespaces, and more.
This article is the first of a three-part series exploring these new features. The current article will focus on simplified configuration and new annotation-based functionality in the core of the Spring application context. The second article will cover new features available in the web-tier, and the final article will highlight additional features available for integration and testing.
If you're currently using the Spring Framework, this is a good opportunity to read about the new features and decide if there's a compelling reason to upgrade. If you're not using the Spring Framework, but considering it, this is a good opportunity to learn about some of the new features that may make your decision easier, or harder. Either way, the Spring Framework is a big part of how many people assemble their Java enterprise applications and Mark Fisher will help guide you through the new features in this article and the two parts yet to come.
Download the Free Adobe® Flex® Builder 3 Trial
Adobe® Rich Internet Application Project Portal
Adobe® Rich Internet Application Project Portal
There seems to be a fair amount of missing or hidden XML in this article. If you look at the HTML source, you'll see where some XML has not been properly escaped.
Matt, You are right. Someone must have edited this recently, because the XML was showing up properly before. I just sent a mail to the editor. Thanks, Mark
Hi Matt, Mark The XML has been fixed now. Best Diana
I am really looking forward to using these new features, great job guys. By the way Mark, your sudden and unexplained use of the p: namespace might freak people out. In your explanation of the lifecycle annotations you declare the datasource using the p: namespace trick from http://blog.interface21.com/main/2006/11/25/xml-syntax-sugar-in-spring-20/ Unfortunately, many people probably aren't aware of this feature and it isn't actually mentioned in the article.
This is great -- I always liked the annotation-driven style of Guice but didn't want to abandon Spring just for that. Hooray for less XML!
Ray, Thanks for pointing out that blog for the 'p' namespace. Hopefully that will serve as a 'footnote' now for anyone who may be confused by its usage. Those examples are taken directly from the PetClinic application by the way. Thanks, Mark
I have to admit, I'm content to use XML for wiring, myself -- although perhaps when I try the annotations, I'll discover more advantages than I expect. I seem to be in the minority here. That said, I was more impressed by the features here than I expected to be, so next time I start some Spring config., I might give this a try. Sorry about the XML; that might have been my fault, I changed some metadata after the initial publishing, and there are some quirks in the publishing process that Diana's better at handling. ;) I'm looking forward to the next two parts of the article.
Geoffrey
I have to admit, I'm content to use XML for wiring, myself -- although perhaps when I try the annotations, I'll discover more advantages than I expect. I seem to be in the minority here.
The goal of Spring is to be the ultimate component model. That component model can be configured in different ways. There is no perfect one size fits all approach to configuration. Different contributions are merged together by the container. Certainly, annotations have an important place. However, my experience in practice (long predating my creation of Spring) has been that you need to externalize significant parts of your configuration from Java code.
The annotation support in Spring 2.5 is very slick and definitely makes Spring a better product. You can mix and match annotation-driven and XML (and other) configuration so that you can use the appropriate solution for each problem. I'm proud that each version of Spring has made applications easier to build.
I recently presented on Configuring the Spring Container at QCon San Francisco, discussing alternative configuration options and best practices. The slides are available as PDF.
The annotation @Resource is a little confusing in the context of spring. As I saw it I first thought it will be used for ressources and not for beans. Like that: @Ressource("file:out/example.txt") public void setOutput(Ressource ressource) {...}
Jorg I agree that @Resource is a poor name for the annotation, but we didn't choose it... Rgds Rod
as now i can turn everything into a FactoryBeanImpl. @Bonkers(Retention.FORALLTIME) afterPropertiesSet()
Great Job, keep it up Thanks
Good Artical...
Of course...Great
Good material. But where can I find the 2nd part and 3rd part of this series. Thanks.
Not to mention how it's never mentioned how to actually create an instance of the object that is injected by Spring. We see the annotated class, and the
Agreed...this would be very useful.
Darryl Pentz writes:
Not to mention how it's never mentioned how to actually create an instance of the object that is injected by Spring. We see the annotated class, and the configuration XML, but no idea how to construct an instance of the annotated class. Does it appear as if by magic?
I had the same question the first time I read this article (too quickly). The answer lies in the "Auto-Detection of Spring Components". The key "magic" is this tag:
<context:component-scan ... />
which causes Spring to automatically go hunting through your JARs looking for specially-annotated classes. When it finds them, it auto-constructs instances and adds them to your application context. The net effect is a purely annotation-driven (zero XML) way to add and configure individual beans.
Mark, great work, are parts 2 and 3 available yet?
Hey Greg, Did you hear anything about the 2nd and 3rd parts yet?
"While all Spring-managed objects are treated as singleton instances by default, it is sometimes necessary to specify an alternate "scope" for an object. " I believe with the @PostConstruct @PreDestroy, the default should change to "request" or "prototype", not singleton any more... otherwise it is very possibly not thread-safe.... And is there any plan to support more lifecycle/AOP like annoations? like @PreInvoke @PostInvoke....
I wrote a series of posts called "Spring for JEE developers" I describe some of Spring 2.5 new features like partial implementations of JSR 220 and JSR 250. If someone is interested here they are: http://jee-bpel-soa.blogspot.com/2008/11/spring-for-jee-developers-jsr-250.html http://jee-bpel-soa.blogspot.com/2008/11/spring-for-jee-developers-jpa.html http://jee-bpel-soa.blogspot.com/2008/11/spring-for-jee-developers-stateless-ejb.html best regards
Here's the second part (haven't found the third part yet) http://www.infoq.com/articles/spring-2.5-ii-spring-mvc
This presentation focuses on the Internet and separating myth from fact, history from the future, and the mundane from the imaginative. Bob Frankston presents a vision of what could and should be.
This article explores the use of JBoss and jBPM to implement design solutions that effectively address the issue of orchestrating long running activities.
This presentation covers the use of graph databases as an optimal solution for data that is difficult to fit in static tables, rapidly evolving data or data that has a lot of optional attributes.
This session introduces Real Options and shows how it can help in running your project. Real Options is a decision-making process that can be used to manage risk.
This article discusses the use of bindings on services and references (including the instance of non-configured bindings) as the means to implement SCA communications in a Web and SOA environment.
After a short introduction to DSLs, Scott Davis plays with the keyboard showing how to approach the creation of a DSL by typing working snippets of Groovy code that get executed.
IBM Rational and InfoQ present, Scaling Agile with C/ALM, an eBook showing organizations how to become “finely tuned software delivery machines” by enabling team integration and scaling.
Amanda Laucher presents a real life enterprise application written in F#. She shows actual code snippets, explaining design decisions and suggesting how to use some of the F# constructs.
23 comments
Watch Thread Reply