190 likes | 610 Views
Spring framework. History What is Spring Framework Dependency Injection and Inversion of Control Why Spring ?. Spring History. Based on ‘Expert one-on-one J2EE Design and Development ’ by Rod Johnson Open source project since February 2003 Actual version 3.2
E N D
Springframework • History • WhatisSpringFramework • DependencyInjection and InversionofControl • WhySpring ?
SpringHistory • Based on ‘Expert one-on-one J2EE Design and Development’ by Rod Johnson • Open source project sinceFebruary 2003 • Actualversion 3.2 • Maincoredevelopers: • Rod Johnson • JurgenHöller
WhatisSpringFramework? • IntroducingSpringisharderthanmostframeworksbecauseit’s not a single purposetechnology • Springisanopen-sourceapplicationdevelopmentframeworkproducedfor Java and .NET • Spring can bethoughtofas a hugeframeworkof best practicesforalmostevery area of Java softwaredevelopment. • Springsupportsitall and does so with some of the mostwelldesigned and heavilytested code in the Java industry • The Springframeworkhastwocorefeatures • DependencyInjection (DI) • AspectOrientedProgramming (AOP)
Data Access & integration Web & remoting • Springcomponents and features JDBC ORM Web Portlet Transaction OXM JMS Servlet Struts AOP Instrumentation AOP Aspects Instrument InstrumentTomcat CoreSpring container Beans Core Context Expression Contextsupport Testing Test
InversionofControl (IOC) or DependencyInjection • DependencyInjection • Beansdefinetheirdependenciesthroughconstructorarguments or properties • The container provides the injection at runtime • Decouplesobjectcreators and locatorsfromapplicationlogic • Easy tomantain end reuse • Easy testing • The IOC container is the corecomponentof the Springframework • Isresponsibleofcontaining and managingbeans • Springcomeswithtwotypesofcontainers • BeanFactory • ApplicationContext
BeanFactory • Provides basic support for dependency injection • Responsiblefor • Creating and dispensingbeans • Managingdependenciesbetweenbeans • ApplicationContext • Built on top of the BeanFactory • Provides more enterprise-centricfunctionalities • Internazionalization • AOP transaction management • Mostcommonlyusedimplementationis the ClassPathXmlApplicationContext ResourcexmlFile = newClassPathResource( "META-INF/beans.xml" ); BeanFactorybeanFactory = newXmlBeanFactory( xmlFile); MyBeanmyBean = (MyBean) beanFactory.getBean( myBean ); StringxmlFilePath = "META-INF/beans.xml”; ApplicationContextcontext = newClassPathXmlApplicationContext( xmlFilePath); MyBeanmyBean = (MyBean) context.getBean( myBean );
Bean Scopes • A beandefinitionis a recipeforcreatinginstances • Manyobjectinstances can becreatedby a single definition • Springmanagethe scope of the beansforyou • No needfordoingitprogrammatically
AOP • Crosscutting concerns • Functionality whose implementation spans multiple modules • Many examples: Logging and tracing, Transaction management, security, caching, error handling, business rules, performance monitoring… • Whatis AOP? • A programming methodology to help with crosscutting concerns • Core AOP concepts: • Advice: the job of an aspect, the what and when • Join point: a point In the execution of an application where an aspect can be plugged in • Point cuts: the where of an aspect, matches one or more Join Points • Aspects: mergers of advices and poincuts
WhySpring? • Itaddressesimportant areas that many other popular frameworks don't. • Spring is both comprehensive and modular • Spring is designed from the ground up to help you write code that's easy to test • Spring is an increasingly important integration technology with our existing frameworks • Great documentation and community support