Advance Java Practical Journal
ISBN 9788119221226

Highlights

Notes

  

Annexure – II: How to run Java Spring program using Eclipse

What is Spring Framework?.

This framework is a part of J2EE Enterprise edition. It having in-built classes , methods and packages written using Java code and its compiled files are group together into one jar file or memory areas.

Using this inbuilt java code, end user only customize its requirements and get the output.

Using Spring framework, we can develop Client side, Server side and database side application.

Spring framework having three features

    1. Simplicity

    2. Testability

    3. Loose coupling

Simplicity

Spring framework program is simple because it is non-invasive as it uses POJO and POJO model.

POJO (Plain Old Java Object)

A java class not coupled with any other technology or any framework is called as POJO class.

POJI (Plain Old java Interface)

A java interface not coupled (dependent or connected) with any technology or any framework is called POJI.

Hence we have inbuilt classes and interface in Spring framework with customization according to End user requirements

Testability:

For writing the Java code using Spring framework, sever is not mandatory to installed into any IDE.

In case of EJB and Struts, to run or compilation we require Server and but making changes into its software we have to reset Server configuration each time.

In case of Spring Framework, it is having their own container to run the application.

Loose Coupling

Spring Framework is loosely coupled because it having concept like Dependancy Injection (DI) and Aspect Oriented Programing . Means it won’t totally depend on core java classes and methods.

OLA - > Electric (Start)

Honda-> Petrol

Yazdi - < Disel

https://repo.spring.io/ui/native/release/org/springframework/spring/

another zip file to download

https://jar-download.com/artifacts/commons-logging/commons-logging/1.2/source-code

package demo.org;

public class HelloWorldSpring {

String name;

public void getName() {

System.out.println(“ Hello “+name+” Welcome to Spring World”);

}

public void setName(String name) {

this.name = name;

}

}

package demo.org;

import org.springframework.context.ApplicationContext;

import org.springframework.context.support.ClassPathXmlApplicationContext;

public class MainApp {

public static void main(String[] args) {

// TODO Auto-generated method stub

ApplicationContext context = new ClassPathXmlApplicationContext(“Beans.xml”);

HelloWorldSpring obj = (HelloWorldSpring)context.getBean(“vikram”);

}

}

Open following link for Bean xml file format.

https://docs.spring.io/spring-framework/docs/4.2.x/spring-framework-reference/html/xsd-configuration.html

<?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.xsd>

<bean id=“vikram” class=“demo.org.HelloWorldSpring”>

<property name=“name” value=“Hritik”/>

</bean>

</beans>