|
|
Optimize with a SATA RAID Storage Solution
Range of capacities as low as $1250 per TB. Ideal if you currently rely on servers/disks/JBODs
Page 5 of 5
The lang schema defines components for handling tasks related to exposing objects written in dynamic languages such as Groovy and
JRuby.
The preamble entries for the lang namespace are specified as shown in bold in the following snippet:
<?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:lang="http://www.springframework.org/schema/lang"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/lang
http://www.springframework.org/schema/lang/spring-lang-2.0.xsd">
<!-- <bean/> definitions here -->
</beans>
See the Resources section for more information about the lang schema.
The aop schema defines components for handling tasks related to AOP configuration in Spring, including Spring's proxy-based framework,
and integrating Spring with AspectJ.
The preamble entries for the aop namespace are specified as shown in bold in the following snippet:
<?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:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
<!-- <bean/> definitions here -->
</beans>
See the Resources section for more information about the aop schema.
The tx schema defines components that provide support for transactions in the Spring framework.
The preamble entries for the tx namespace are specified as shown in bold in the following snippet:
<?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:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/util/spring-tx-2.0.xsd">
<!-- <bean/> definitions here -->
</beans>
See the Resources section for more information about the tx schema.
Spring 2.5 provides support for scanning the classpath in order to identify components. You can facilitate scanning by applying
the proprietary stereotype annotation @Component to a given class.
The @Component annotation specifies that the annotated class is a component, as Listing 12 shows.
package com.jeffhanson.spring.beans;
@Component
public class Foobar implements IHelloWorld
{
private String message = "Hello World!";
public void setMessage(String message)
{
this.message = message;
}
public String getMessage()
{
return message;
}
public void sayHello()
{
System.out.println(message);
}
}
When Spring discovers components using classpath scanning, the bean definitions are generated for the components, which are automatically registered with Spring. Note the following configuration file:
<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"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd">
<context:annotation-config />
<context:component-scan base-package="com.jeffhanson.spring.beans" />
<!-- <bean/> definitions here -->
</beans>
The <context:component-scan annotation declaration in Listing 12 enables autodetection of any annotated classes in the package com.jeffhanson.spring.beans.
Classpath scanning simplifies the work needed to declare your classes as components in the Spring framework. This mechanism is most effective when you do not anticipate frequent changes to the relationships between beans and/or components.
The Spring framework is an open source staple for many Java server-side developers, and one of the foremost platforms for building Java applications and services for the enterprise. Spring's popularity is largely owed to the fact that it hides a great deal of infrastructure detail, allowing developers to focus primarily on immediate tasks. Spring's simplicity is facilitated by its pervasive use of inversion of control, aspect-oriented programming, and dependency injection for simple Java beans.
The Spring 2.0 and Spring 2.5 releases have further promoted the simplicity of Spring. In this article you have walked through a Spring component development scenario using some of the new features found in Spring 2.0 and Spring 2.5, including custom namespaces and support for XSD data and Java 5 annotations. You've also seen several of the new built-in schemas found in Spring 2.5, for custom components that handle common programming tasks such as AOP integration and transaction handling.
DefaultBeanDefinitionDocumentReader for handling custom namespaces in a Spring XML configuration file.
Archived Discussions (Read only)