13.07.2015 Views

Spring JavaConfig Reference Guide - Spring Web Services - Parent ...

Spring JavaConfig Reference Guide - Spring Web Services - Parent ...

Spring JavaConfig Reference Guide - Spring Web Services - Parent ...

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 1. Overview1.1. What is <strong>JavaConfig</strong>?<strong>Spring</strong> <strong>JavaConfig</strong> is a product of the <strong>Spring</strong> community that provides a pure-Java approach to configuring the<strong>Spring</strong> IoC Container. While <strong>JavaConfig</strong> aims to be a feature-complete option for configuration, it can be (andoften is) used in conjunction with the more well-known XML-based configuration approach.See Section 8.1, “<strong>JavaConfig</strong> and XML” for more information on using <strong>JavaConfig</strong> and XML together1.2. Why <strong>JavaConfig</strong>?The <strong>Spring</strong> IoC Container is the leading dependency injection framework. It provides sophisticated dependencyinjection capabilities as well as advanced features for aspect-oriented programming. Today the majority of<strong>Spring</strong> users configure the <strong>Spring</strong> container using XML. This works very well, and in many cases is ideal.However, some developers find configuring the <strong>Spring</strong> container via Java a more natural or appropriateapproach, for a variety of reasons.Motivations of <strong>JavaConfig</strong> include:Object-oriented configuration. Because configurations are defined as classes in <strong>JavaConfig</strong>, users can takefull advantage of object-oriented features in Java. One configuration class may subclass another, overriding its@Bean methods, etc.Reduced or eliminated XML configuration. The benefits of externalized configuration based on theprinciples of dependency injection have been proven. However, many developers would prefer not to switchback and forth between XML and Java. <strong>JavaConfig</strong> provides developers with a pure-Java approach toconfiguring the <strong>Spring</strong> container that is conceptually similar to XML configuration. It is technically possible toconfigure the container using only <strong>JavaConfig</strong> configuration classes, however in practice many have found itideal to mix-and-match <strong>JavaConfig</strong> with XML. See Section 8.1, “<strong>JavaConfig</strong> and XML” for details.Type-safe and refactoring-friendly. <strong>JavaConfig</strong> provides a type-safe approach to configuring the <strong>Spring</strong>container. Thanks to Java 5.0's support for generics, it is now possible to retrieve beans by type rather than byname, free of any casting or string-based lookups. See Section 4.3.2.1, “Type-safe access” for details.1.3. Requirements1.3.1. Runtime Environment<strong>JavaConfig</strong> takes full advantage of Java 5.0 language features, especially annotations and generics. A Java 5.0+runtime environment is a requirement for using <strong>JavaConfig</strong>.. For an introduction to annotations and other Java5.0 features, see http://java.sun.com/docs/books/tutorial/java/javaOO/annotations.html andhttp://java.sun.com/j2se/1.5.0/docs/relnotes/features.html#lang1.3.2. Project DependenciesEvery effort has been made to reduce the number of dependencies <strong>Spring</strong> <strong>JavaConfig</strong> requires. For very simple<strong>Spring</strong> <strong>JavaConfig</strong> 2

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!