Spring module

SPRING MODULE

0  0 2017-01-04 09:37:45

The Spring framework set of many modules such as JDBC, Struts, Servlet, Web, nstrumentation, expression language, core, beans, ORM, OXM, JMS, AOP, context, Aspects, Transaction etc. so all modules are grouped into Data Access / Integration, Core Container, AOP, Test, Instrumentation, Aspects, Web (MVC / Remoting) as mentioned below.

Test
Test layer provides support of testing with TestNG and JUnit.

Spring Core Container
This layer contains expression language (EL), core, context and beans modules.

Core and Beans
This two modules Core and Beans provide Inversion of Control (IoC) and Dependency Injection features.

Context
Context module supports internationalization, JMS, EJB, Basic Remoting.

AOP, Aspects and Instrumentation
AOP, Aspects and Instrumentation modules support aspect oriented programming implementation where we can use Pointcuts, Advices etc.

Instrumentation
This module support to class-loader implementations and instrumentation.

Data Access / Integration
JDBC, JMS, OXM, ORM and Transaction modules. This modules support to interact with the database.

Web
Web, Web-Struts, Web-Portlet and Web-Servlet, These modules are useful for create web application.

Steps for developing spring application
1) Create Java class
simple java class contains the designation property.

package com.javas;  
public class Employee
{  
    private String desig;  
    public String getDesig ()
    {  
        return desig;  
    }  
 
    public void setDesig (String desig)
    {  
        this. desig = desig;  
    }  
    public void showInfomation()
    {  
        System.out.println("Hi : "+ desig);  
    }  
}  
above is simple java class, which contains property desig with its getters and setters method.

2) Create XML file
In case of Myeclipse IDE, you don't need to create the xml file as myeclipse does this for yourselves.
Open the applicationContext.xml file, and write down below code in that file
<?xml version="1.0" encoding="UTF-8"?>  
<beans  
    <bean id="employeebean" class="com.javas.Employee">  
    <property desig=" desig " value="Senior Analyst "></property>  
    </bean>  
  </beans>  

3) Create test class
Create a one java class e.g. Demo. Here we are getting the object of Employee class from the IOC container using the getBean() method of BeanFactory.

package com.javatpoint;  
import org.springframework.beans.factory.BeanFactory;  
import org.springframework.beans.factory.xml.XmlBeanFactory;  
import org.springframework.core.io.ClassPathResource;  
import org.springframework.core.io.Resource;  

public class Demo
{  
    public static void main(String args[] )
    {  
        Resource resource=new ClassPathResource("applicationContext.xml");  
        BeanFactory factory=new XmlBeanFactory(resource);  
        Employee employee  = ( Employee ) factory.getBean(" employeebean ");  
        employee.showInformation();  
    }  
}  
The Resource is the interface and the ClassPathResource class implements the Reource interface. So applicationContext.xml file information represents by the Resource object. The BeanFactory is responsible to return the bean. So BeanFactory is implemented by the XmlBeanFactory class. There are many methods in the BeanFactory interface. Method getBean() is from same interface, which returns the object of the associated class.

 

Comments (0)

Post Your Comments

Headquarter



Hong Kong Office



Find Us On

Ziuby
Ziuby