Spring framework
Upcoming SlideShare
Loading in...5

Spring framework



Spring workshop at Capegemini Pune on 15th June 2012 presented by Rajkumar Singh

Spring workshop at Capegemini Pune on 15th June 2012 presented by Rajkumar Singh



Total Views
Views on SlideShare
Embed Views



47 Embeds 813

http://rajkrrsingh.blogspot.com 264
http://rajkrrsingh.blogspot.in 181
http://www.rajkrrsingh.blogspot.in 80
http://www.rajkrrsingh.blogspot.com 24
http://rajkrrsingh.blogspot.de 23
http://rajkrrsingh.blogspot.jp 20
http://rajkrrsingh.blogspot.co.uk 18
http://rajkrrsingh.blogspot.kr 17
http://www.linkedin.com 14
http://rajkrrsingh.blogspot.sg 14
http://rajkrrsingh.blogspot.mx 13
http://rajkrrsingh.blogspot.fr 12
http://rajkrrsingh.blogspot.com.br 11
http://rajkrrsingh.blogspot.it 11
http://rajkrrsingh.blogspot.ca 9
http://rajkrrsingh.blogspot.com.es 8
http://rajkrrsingh.blogspot.com.ar 8
http://www.rajkrrsingh.blogspot.se 8
http://rajkrrsingh.blogspot.com.au 7
http://rajkrrsingh.blogspot.ru 7
http://rajkrrsingh.blogspot.ch 5
http://rajkrrsingh.blogspot.ie 5
http://rajkrrsingh.blogspot.co.il 5
http://rajkrrsingh.blogspot.fi 4
http://rajkrrsingh.blogspot.hk 4
http://theexamtime.com 3
http://rajkrrsingh.blogspot.se 3
http://webcache.googleusercontent.com 3
http://www.rajkrrsingh.blogspot.it 3
http://rajkrrsingh.blogspot.dk 3
http://rajkrrsingh.blogspot.be 3
http://rajkrrsingh.blogspot.nl 2
http://rajkrrsingh.blogspot.co.at 2
http://rajkrrsingh.blogspot.tw 2
http://rajkrrsingh.blogspot.ro 2
http://rajkrrsingh.blogspot.cz 2
http://www.rajkrrsingh.blogspot.co.uk 2
http://www.verious.com 2
http://www.rajkrrsingh.blogspot.ae 1
http://www.rajkrrsingh.blogspot.com.es 1
http://rajkrrsingh.blogspot.pt 1
http://rajkrrsingh.blogspot.co.nz 1
http://www.rajkrrsingh.blogspot.ca 1
http://rajkrrsingh.blogspot.sk 1
http://www.rajkrrsingh.blogspot.de 1
http://www.rajkrrsingh.blogspot.nl 1
http://rajkrrsingh.blogspot.gr 1



Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
  • Nice information, there is a type-o on slide 25 'CGILIB' should be 'CGLIB'. I would recommend making all the other URLs on slide 25 hyperlinks.
    Are you sure you want to
    Your message goes here
Post Comment
Edit your comment

Spring framework Spring framework Presentation Transcript

  • Workshop of Spring Application Framework at Capegemini Presented By Rajkumar Singh www.rajkrrsingh.blogspot.com
  • AgendaIntroductionSpring ArchitectureSpring BeansSpring IOCSetting up Spring EnvironmentBeans Life cyclesSpring DAOSpring ORMSpring AOPQ&A www.rajkrrsingh.blogspot.com
  • IntroductionSpring framework was initially written by Rod Johnson andwas first released under the Apache 2.0 license in June2003.Primary purpose is to reduce the dependencies(loosecouple)Spring deliver many significant benefits to the developersreducing development effort and cost while improving testcoverage and qualityHandle the infrastructure so that developer can focus onthe development onlyEnables you to build application from POJOsSpring does not recreate all the framework but make use ofthe existing one like ORM,logging,JEE framework. www.rajkrrsingh.blogspot.com
  • What Spring OffersDependency InjectionAspect Oriented Programming (AOP)Portable Serives ORM DAO MVC www.rajkrrsingh.blogspot.com
  • Application LayeringPresentation Layer Spring MVC Spring Web Service Layer Gateway to expose business logic to the outside worldPersistence Layer Not well defined in many applications today or tightly coupled in an inappropriate layer. JDBC ORM Manages ‘container level services’ Eg. transactions, security, data access logic, and manipulates domain objectsDomain Layer POJOs www.rajkrrsingh.blogspot.com
  • Spring Architecture www.rajkrrsingh.blogspot.com
  • Spring ArchitectureCore & Beans:Provides fundamental functionality & Dependency Injection features.Primary component is the BeanFactory (Factory pattern )The Context moduleBuilds on the base modules.Access objects in a framework-style manner similar to a JNDI registry.Also supports Java EE features such as EJB, JMX ,and basic remoting.The ApplicationContext interface is the focal point of the module.The Expression Language moduleProvides a powerful expression language for querying andmanipulating an object graph at runtime. www.rajkrrsingh.blogspot.com
  • Spring ArchitectureThe JDBC modulea JDBC-abstraction layer that removes tediousJDBC coding, parsing of database-vendor specific error codes.The ORM moduleintegration layers for ORM APIs, including JPA, JDO, Hibernate, & iBatis.The OXM module supportsObject/XML mapping implementations for JAXB, Castor, XMLBeans, JiBX and XThe JMS Modulecontains features for producing and consuming messages. The Transaction module supports programmatic and declarative transaction management www.rajkrrsingh.blogspot.com
  • Spring ArchitectureSprings Web moduleprovides basic web-oriented integration features(multipart file-upload)initialization of the IoC container using servlet listenersWeb ServletSprings model-view-controller (MVC)The Web-Struts modulecontains Support classes for integrating a classic Struts web tier within a Spring application.The Web-Portlet moduleprovides the MVC implementation to be used in a portlet environment www.rajkrrsingh.blogspot.com
  • Spring IOCInversion of control is all about Object DependenciesTraditional Object Creation Approach Direct Object Creation new Employee() FactoryImplementation EmpFactory().getEmp() JNDI Services naming.lookup()Spring ApproachSpring Container creates all the objects,wires them together by setting the necessaryproperties, and determines when methods willbe invoked. www.rajkrrsingh.blogspot.com
  • Spring ContainerFundamental part of the framework.Two packages provides the basis for the Spring Frameworks IoC container.– org.springframework.beans– org.springframework.contextBeanFactory provides the configuration framework and basic functionality,and the ApplicationContext adds more enterprise-specific functionality.The org.springframework.beans.factory.BeanFactory is the actual representatithe Spring IoC containerResponsible for containing and managing beans.The most commonly used BeanFactory implementation is the XmlBeanFactorThe XmlBeanFactory takes XML configuration metadata and uses it to createconfigured system or application. www.rajkrrsingh.blogspot.com
  • Spring ContainerThe interface org.springframework.context.ApplicationContext represents theSpring IoC container and is responsible for instantiating, configuring, andassembling the beans.The container gets its instructions by reading configuration metadata.The configuration metadata is represented in XML and Java annotationsSeveral implementations of the ApplicationContext interface are supplied with Spring.In standalone applications it is common to create an instance ofClassPathXmlApplicationContext or FileSystemXmlApplicationContext www.rajkrrsingh.blogspot.com
  • Ways To Initialize Spring Container www.rajkrrsingh.blogspot.com
  • Type of Dependency Injection Setter method Injection Constructor Injection Configuration File Injection www.rajkrrsingh.blogspot.com
  • Examples for dependency InjectionSetup Enviornment for SpringInstall JAVAIf you are running Windows and installed the JDK in C:jdk1.6.0_15, you would have toput the following line in your C:autoexec.bat file.set PATH=C:jdk1.6.0_15bin;%PATH%set JAVA_HOME=C:jdk1.6.0_15Unix (Solaris, Linux, etc.), if the SDK is installed in /usr/local/jdk1.6.0_15 and you use theC shell, you would put the following into your .cshrc file.setenv PATH /usr/local/jdk1.6.0_15/bin:$PATH setenv JAVA_HOME /usr/local/jdk1.6.0_15Download Spring JarsInstall Common LoggingDownload Apache Commons Logging API from http://commons.apache.org/loggingInstall Eclipse and setup for Spring www.rajkrrsingh.blogspot.com
  • Reference to Other Beans (DI) www.rajkrrsingh.blogspot.com
  • Some More ExampleAliasImportInitialize bean static Bean Factory Method <bean id="mp3ply" class="com.test.Mp3Player" factory-method="factoryMethod"> </bean> public Class Mp3Player{ private static Mp3Player mp3ply = new Mp3Player(); public Mp3Player(){} public static Mp3Player factoryMethod(){ return mp3ply; } } www.rajkrrsingh.blogspot.com
  • Some More ExampleCollectionsInner BeansAutowireNamespacesDepends UponApplicationContextAware interfaceBeanNameAware interfaceInitializingBean interface www.rajkrrsingh.blogspot.com
  • Beans ScopesScope Description This scopes the bean definition to a single instance persingleton Spring IoC container (default). This scopes a single bean definition to have any number ofprototype object instances. This scopes a bean definition to an HTTP request. Onlyrequest valid in the context of a web-aware Spring ApplicationContext. This scopes a bean definition to an HTTP session. Onlysession valid in the context of a web-aware Spring ApplicationContext. This scopes a bean definition to a global HTTP session.global-session Only valid in the context of a web-aware Spring ApplicationContext. www.rajkrrsingh.blogspot.com
  • Beans Life Cycle When a bean is instantiated, it may be required to perform some initializatioto get it into a usable stateWhen the bean is no longer required and is removed from the container,some cleanup may be required.Register the shutdown hook for the ApplicationContextCallback Methods: Init and destroy methods The init-method attribute specifies a method that is to be called on the bean immediately upon instantiation destroy-method specifies a method that is called just before a bean is removed from the container. www.rajkrrsingh.blogspot.com
  • Beans Post Processors The BeanPostProcessor interface defines callback methods that you can implement to provide your own instantiation logicYou can also implement some custom logic after the Spring container finishe instantiating, configuring, and initializing a bean by impl PostProcessorsYou can have multiple Bean Post processor and can define their order of executionApplicationContext automatically detects any bean as a post processor whoimplements BeanPostProcessor Interface www.rajkrrsingh.blogspot.com
  • Aspect Oriented Programming(AOP) ObjectA ObjectC methodA() methodA() . . . . methodN() methodN()v Logging Security Aspect Configuration ObjectB ObjectD methodA() methodA() . . . . methodN() methodN() www.rajkrrsingh.blogspot.com
  • Aspect Oriented Programming(AOP)Complements OO programmingAspect Oriented Programming entails breaking down program logic into dist parts called so-called concernsCross-cutting concerns are conceptually separate from the applications business logic, e.g. ogging, auditing, declarative transactions, security, and caching etcSpring AOP module provides interceptors to intercept an application, for example, when a method is executed, you can add extra functionality before or after the method execution. www.rajkrrsingh.blogspot.com
  • Aspect Oriented Programming(AOP)Components of AOP Aspect – unit of modularity for crosscutting concerns Join point – well-defined points in the program flow Pointcut – join point queries where advice executes Advice – the block of code that runs based on the pointcut definition Weaving – can be done at runtime or compile time. Inserts the advice (crosscutting concerns) into the code (core concerns). www.rajkrrsingh.blogspot.com
  • Setting up AOP Environment in EclipseAOP Dependencies AspectJ: http://www.eclipse.org/aspectj/downloads.php AOP Alliance: http://aopalliance.sourceforge.net/ CGILIB: http://cglib.sourceforge.net/ Spring 3 ASM: http://asm.ow2.org/ Examples….. www.rajkrrsingh.blogspot.com
  • Spring DAO and ORM Built in code templates that support JDBC, Hibernate, JDO,and iBatis SQL MapsSimplifies data access coding by reducing redundant code andhelps avoid common errors. Alleviates opening and closing connections in your DAO code.No more ThreadLocal or passing Connection/Session objects.Transaction management is handled by a wired beanYou are dropped into the template with the resources you needfor data access – Session, PreparedStatement, etc.Optional separate JDBC framework www.rajkrrsingh.blogspot.com
  • JdbcTemplateCentral class in the JDBC core packageHandles the creation and release of resources.Executes the core JDBC workflow like statement creationandExecution Executes – SQL queries – update statements – stored procedure calls – iteration over ResultSets – extraction of returned parameter values.Also catches JDBC exceptions www.rajkrrsingh.blogspot.com
  • DataSource Configuration www.rajkrrsingh.blogspot.com
  • Spring ORM : Working with Hibernate www.rajkrrsingh.blogspot.com
  • Spring ORM : Working with Hibernate www.rajkrrsingh.blogspot.com
  • Q&A www.rajkrrsingh.blogspot.com
  • Thanksif you have any query concerns write to me on rajkrrsingh@gmail.com www.rajkrrsingh.blogspot.com