Now this is a session that by just glancing at the title and the slides I know it’s going to be good. My co-worker Phil HATES Spring mainly because he hates XML files (at least from what I’ve noticed from his knee jerk reaction when he sees an XML configuration file). So, I’m ready to learn something about Spring 2.5! ;)

The presentation has started off exceedingly good… Ken Sipe started the session by finding out what the need of the audience as he began the presentation. With a quick overview of the frustrations of Spring 2 (autowiring feeling too “magical”, long XML, required injections), what’s going away, and what started, Ken began moving towards the meat of the presentation: Annotations.

Spring 2.5 has a ot of annotation support, both for it’s own annotations as well as JSR-250 javax annotations, EJB annotations, and many more. Of interest is the @Repository annotation, which indicates a class functions as a repository and proxies it, converting any checked exceptions to unchecked exceptions.

Aspects

There’s a new pointcut for pointcuts in Spring 2.5 that allows pointcuts for beans as well as both vertical and horizontal stack selection (i.e. accountController -> accountService ->accountDAO). These are Spring only and not for AspectJ.

Stereotypes

He abriefly covered the Stereotype annotations that indicate “class types.” These include @Component, @Controller, @Repository, and @Service.

Factory Annotations

@Autowired is the first one mentioned… and for good reason. This annotation, as the name implies, implements autowiring of fields, constructors, setters, or config methods. There is also a lot of fine grained control over the autowiring. The @Qualifier annotation both qualifies a bean for autowiring and also allows for customization.

@Required marks a method as being “injection required.”

javax Annotations

What was noticible here was the @Resource annotation, which is used for injecting named resources (must be the Spring name, not the JNDI name). It’s also a debated whether to use @Resource or @Autowired … it’s up to the teams. ;)

Thankfully at this point Ken stepped back and pulled up a demo making use of these annotations… pretty nifty, and it was quite interesting to see how this all glues together in a simple easy to follow application. The nice thing was that although an xml file was there, it only had 3 entries in it (a comparable example with everything in his app in Spring 2.0 would easy be a few pages of XML). The coolest thing I saw here was the autowired method names could be changed and they still got injected perfectly fine. :)

Spring MVC has a lot of nice annotations for configuration/specifying input/output, but I’m not into Spring MVC much… maybe I’ll come back and cover it later. Looks solid though.

The reduction of XML was covered even further… such as using <context:component-scan/> to include/exclude classes as beans. This was covered lighty… this just helps reduce the ammount of beans you need to define. You can also jsut move some properties out of XML… <context:property-placeholder/> is useful here… you can just specify a property file, which simpler and more concise than XML).

Spring with NO XML

You can use Java based configuration. Just marking a class as @Configurable allows you to just use the class for getting beans. Also, you can write your own parser that uses something besides XML to define configuration. This isn’t new though… its been around for Spring 2.0.

Auto-Discovery is where the meat is… you can set up a scanner that simply scans your packages and refreshes the context with the beans that currently exist. NIFTY!

All in all it was a very informative and fun presentation… I think I may attend the next session with the same presenter. ;)

Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Google
  • BlogMemes
  • Blogosphere News
  • description
  • Fark
  • LinkedIn
  • NewsVine
  • StumbleUpon
  • Technorati
  • TwitThis
  • Yahoo! Buzz

If you're new here, you may want to subscribe to my RSS feed. Thanks for visiting!