Datasheet
Note the XML schema and namespaces used in the <beans> document element. These are standard for
Spring 2.0 and the schema defines the tags allowed within the descriptor. You are likely to find these
schema in every Spring context descriptor file, except for some pre-2.0 legacy DTD-based descriptor
files. (See the sidebar Support of Legacy DTD-Based Spring Wiring Syntax.)
<?xml version=”1.0” encoding=”UTF-8”?>
<beans xmlns=”http://www.springframework.org/schema/beans”
xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance”
xsi:schemaLocation=”http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd”>
<bean id=”screen” class=”com.wrox.begspring.ScreenWriter” />
<bean id=”multiply” class=”com.wrox.begspring.OpMultiply” />
<bean id=”add” class=”com.wrox.begspring.OpAdd” />
<bean id=”opsbean” class=”com.wrox.begspring.CalculateSpring”>
<property name=”ops” ref=”multiply” />
<property name=”writer” ref=”screen”/>
</bean>
</beans>
ClassPathXmlApplicationContext is part of the Spring container, and it looks for the context descrip-
tor (
beans.xml) in the Java VM’s CLASSPATH and creates an instance of an ApplicationContext from
it. During the instantiation of the
ApplicationContext, the beans are wired by the Spring container
according to the directions within the context descriptor.
Creating and Wiring Java Beans
The <bean> tag, as its name suggests, is used to instantiate an instance of a bean. The container per-
forms the following actions according to the instructions:
1. Creates an instance of ScreenWriter and names the bean screen
Support of Legacy DTD-Based Spring Wiring Syntax
Note that you may also frequently see Spring configuration files using the following
document based on document type definition (DTD):
<?xml version=”1.0” encoding=”UTF-8”?>
<!DOCTYPE beans PUBLIC “-//SPRING//DTD BEAN 2.0//EN”
“http://www.springframework.org/dtd/spring-beans-2.0.dtd”>
<beans>
...
</beans>
This convention is used extensively in versions of Spring before 2.0. XML schema
offers far more extensive functionality than DTDs. Although Spring 2 supports
DTD-based configurations, it is highly recommended that you use XML schema-
based configurations instead. An example of such a configuration can be seen
above in the
beans.xml file.
12
Chapter 1: Jump Start Spring 2
01612c01.qxd:WroxPro 10/31/07 10:42 AM Page 12










