chapter. In the section on Spring configuration, we will prepare two configuration files throughout the
samples. One is app-context-xml.xml for the XML-style configuration, and the other is app-context-
annotation.xml for the annotation-style configuration.
Listing 4-14. Spring XML Configuration
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:c="http://www.springframework.org/schema/c"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util-3.1.xsd">
</beans>
From the previous namespace declaration, we have made beans the default namespace. The
following namespaces were also declared:
context: The context namespace provides support for configuring Spring's
ApplicationContext.
p: The p namespace provides a simpler DI configuration for Setter Injection.
c: New in Spring 3.1, the c namespace provides a more simple DI configuration
for Constructor Injection.
util: The util namespace provides some useful utilities for DI configuration.
Spring also provides a lot of namespace for various purpose, such as aop for AOP support, tx for
transaction support, and so on. Those namespaces will be covered in the appropriate chapters.
To use Spring's annotation support in your application, you need to declare the tags shown in
Listing 4-15 in your XML configuration (app-context-annotation.xml).
Listing 4-15. Spring XML Configuration with Annotation Support
// Namespace declarations skipped
<context:annotation-config/>
<context:component-scan base-package="com.apress.prospring3.ch4.annotation" />
The <context:annotation-config> tag tells Spring to scan the codebase for dependency
requirements, while the <context:component-scan> tag tells Spring to scan the code for injectable beans
under the package (and all its subpackages) specified. In the <context:component-scan> tag, multiple
packages can be defined by using either a comma, a semicolon, or a space as the delimiter. Moreover,
the tag support inclusion and exclusion of components scan for more fine-grained control. For example,
consider the configuration in Listing 4-16.
Search WWH :
Custom Search
Previous Page
Spring Framework 3 Topic Index
Next Page
Spring Framework 3 Bookmarks
Home