Chapter 3. Minimizing XML configuration in Spring

 

This chapter covers

  • Automatic bean wiring
  • Automatic bean discovery
  • Annotation-oriented bean wiring
  • Java-based Spring configuration

So far, we’ve seen how to declare beans using the <bean> element and inject <bean> with values using either the <constructor-arg> or <property> element. That’s all well and good for a small application where you only have a handful of beans. But as your application grows, so will the amount of XML configuration you’ll write.

Fortunately, Spring offers a few tricks to help cut down on the amount of XML configuration required:

  • Autowiring helps reduce or even eliminate the need for <property> and <constructor-arg> elements by letting Spring automatically figure out how to wire bean dependencies.
  • Autodiscovery takes autowiring a step further by letting Spring figure out which classes should be configured as Spring beans, reducing the need for the <bean> element.

When used together, autowiring and autodiscovery can dramatically reduce the amount of XML Spring configuration. Often you’ll need only a handful of lines of XML, regardless of how many beans are in your Spring application context.

3.1. Automatically wiring bean properties

 
 

3.2. Wiring with annotations

 
 
 
 

3.3. Automatically discovering beans

 
 

3.4. Using Spring’s Java-based configuration

 
 
 

3.5. Summary

 
 
sitemap

Unable to load book!

The book could not be loaded.

(try again in a couple of minutes)

manning.com homepage
test yourself with a liveTest