+ All Categories
Home > Technology > Introduction to Spring Framework

Introduction to Spring Framework

Date post: 14-Feb-2017
Category:
Upload: raveendra-r
View: 76 times
Download: 4 times
Share this document with a friend
14
Introduction to Spring Framework www.collaborationtech.co.in Bengaluru INDIA Presentation By Ramananda M.S Rao
Transcript
Page 1: Introduction to Spring Framework

Introduction to Spring Framework

www.collaborationtech.co.inBengaluru INDIA

Presentation By Ramananda M.S Rao

Page 2: Introduction to Spring Framework

ContentContentIntroduction MVC Architecture Spring Configuration Get Started Dependency Injection The Spring Container(IOC) and API Spring and Hibernate Integration Spring AOP Transaction Management Spring Data ValidationAdvanced techniquesSpring Controllers and AjaxRestful Web Services

www.collaborationtech.co.in

Page 3: Introduction to Spring Framework

ContentRemoting and clustering Spring Security Java Message Service (JMS)JMXSpring OXM(Object XML Mapping) Test-driven DevelopmentFuture ExplorationSpring Best PracticesProjectAbout Us

www.collaborationtech.co.in

Page 4: Introduction to Spring Framework

Introduction Spring framework makes the easy development of JavaEE

application. Spring is a lightweight framework. It can be thought of as a

framework of frameworks because it provides support to various frameworks such as Struts, Hibernate, Tapestry, EJB, JSF etc.

Spring framework comprises several modules such as IOC, AOP, DAO, Context, ORM, WEB MVC etc.

Spring framework was initially written by Rod Johnson and was first released under the Apache 2.0 license in June 2003.

www.collaborationtech.co.in

Page 5: Introduction to Spring Framework

Spring MVC Architecture Spring MVC helps in building flexible and loosely coupled web

applications. The Model-view-controller design pattern helps in separating the

business logic, presentation logic and navigation logic. Models are responsible for encapsulating the application data. The Views render response to the user with the help of the model

object. Controllers are responsible for receiving the request from the user

and calling the back-end services.

www.collaborationtech.co.in

Page 6: Introduction to Spring Framework

Get Started Step 1 - Create Java Projectcreate Helloworld.java and Main.java files under the com.collaba.helloworld package.

Helloworld.javapackage com.collaba.helloworld;public class Helloworld { private String message; public void setMessage(String message){

this.message = message; }

public void getMessage(){ System.out.println("Your Message : " + message); }

}www.collaborationtech.co.in

Page 7: Introduction to Spring Framework

Get Started Main.javapackage com.collaba.helloworld;import org.springframework.context.ApplicationContext;Importorg.springframework.context.support.ClassPathXmlApplicationContext;public class Main {

public static void main(String[] args) { ApplicationContext context = new

ClassPathXmlApplicationContext("Beans.xml");Helloworld obj = (Helloworld) context.getBean("helloWorld"); obj.getMessage();

}}

www.collaborationtech.co.in

Page 8: Introduction to Spring Framework

Get Started Step 2 - Create Bean Configuration Filecreate a Bean Configuration file which is an XML file and acts as cement that glues the beans ie. classes together. This file needs to be created under the src directory as shown below:<?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-3.0.xsd"><bean id="helloWorld" class="com.collaba.helloworld.Helloworld"> <property name="message" value="HELLO WORLD!"/> </bean></beans>

Step 3 - Running the ProgramIf everything is fine with your application, this will print the following message in Eclipse IDE's console.

www.collaborationtech.co.in

Page 9: Introduction to Spring Framework

Autowiring in Spring Autowiring feature of spring framework enables you to inject the object dependency

implicitly. It internally uses setter or constructor injection. Autowiring can't be used to inject primitive and string values. It works with reference only.A.Javapackage com.collaba.autowiring;//This class contains reference of B class and constructor and method.public class A { B b; A(){System.out.println("a is created");} public B getB() { return b; } public void setB(B b) { this.b = b; } void print(){System.out.println("hello a");} void display(){ print(); b.print(); } }

www.collaborationtech.co.in

Page 10: Introduction to Spring Framework

Autowiring in SpringB.Java

package com.collaba.autowiring;//This class contains a constructor and method only.public class B { B(){System.out.println("b is created");} void print(){System.out.println("hello b");} }

www.collaborationtech.co.in

Page 11: Introduction to Spring Framework

Autowiring in SpringTest.javapackage com.collaba.autowiring;import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; //This class gets the bean from the applicationContext.xml file and calls the display method.public class Test { public static void main(String[] args) { ApplicationContext context=new ClassPathXmlApplicationContext("applicationContext.xml"); A a=context.getBean("a",A.class); a.display(); } }

www.collaborationtech.co.in

Page 12: Introduction to Spring Framework

Autowiring in SpringapplicationContext.xml<?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:p="http://www.springframework.org/schema/p" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"> <bean id="b" class="com.collaba.autowiring.B"></bean> <bean id="a" class="com.collaba.autowiring.A" autowire="byName"></bean> </beans>

www.collaborationtech.co.in

Page 13: Introduction to Spring Framework

Follow us on SocialFacebook: https://www.facebook.com/collaborationtechnologies/Twitter : https://twitter.com/collaboration09Google Plus : https://plus.google.com/100704494006819853579LinkedIn : https://www.linkedin.com/in/ramananda-rao-a2012545Instagram : https://instagram.com/collaborationtechnologiesYouTube : https://www.youtube.com/channel/UCm9nK56LRbWSqcYWbzs8CUgSkype : facebook:ramananda.rao.7WhatsApp : +91 9886272445

www.collaborationtech.co.in

THANK YOU

Page 14: Introduction to Spring Framework

About Us


Recommended