Java & J2EE Page 2 - Introducing the Spring Framework |
To use the Spring Framework in an application, there are three main steps. They are:
The second step involves an XML file that the Spring Framework uses to understand the configuration. These are the details: Developing the POJO: POJO or Plain Old Java Objects are, essentially, simple JavaBeans. The first step in using the Spring Framework is to wrap the business logic in a JavaBean. For example, if the logic just says hello, the bean will be as follows: public class Hello { private String greeting; public Hello() { } public Hello(String a) { greeting=a; } public String sayhello(String s) { return greeting+s; } public void setGreeting(String a) { greeting=a; } } It is a simple JavaBean with getters and setters. That completes the first step. Mapping the Beans: The beans need to be mapped using XML so that the IoC container can ‘inject’ the required dependency at runtime. The configuration file contains the following entries. They are:
These are the most common entries. They are arranged in a hierarchical manner. Here are the details: Beans is the first entry or tag. It is the root tag/element of the configuration file. It encapsulates the bean tags. The details of the bean are given to the Spring Framework. The details are passed using the attributes of the bean tag. The most commonly used attributes are:
For example, to provide the details for the Hello bean, the bean tag will be as follows: <beans> <bean id=”Hello” class=”org.me.Hello”> : : </bean> <beans>
blog comments powered by Disqus |
|
|
|
|
|
|
|