SlideShare a Scribd company logo
1 of 61
Spring 2.5 Framework


     Dhaval P. Shah




                       1
My Introduction


       6.5+ years of experience in developing/supporting
        enterprise applications

       SCJP 1.4

       SCWCD 1.4




                                                            2
Agenda


    Spring Jump start

    Core Spring

    Spring AOP

    Spring JDBC

    Spring Transaction




                          3
Pre-requisites


     Core Java

     JDBC

     JNDI

     Basic usage of IDE




                           4
What this training is not -


     An expert in Spring

     Having detailed discussion on all the topics of Spring




                                                               5
Spring jump start

      Why Spring?

      Spring overview
          Lightweight

          IOC

          Aspect Oriented

          Container

          Framework




                             6
Spring jump start [Contd.]

      Spring Modules



      Spring overview
          Lightweight

          IOC

          Aspect Oriented

          Container

          Framework



                             7
SPRING - Core




                8
DI / IoC
       Brief history about DI
           Dependency Inversion: Precursor to Dependency Injection

           What is DI?

           DI Vs IOC


       Types of IOC
           Dependency Pull

           Contextualized Dependency Lookup (CDL)


       Types of DI
           Constructor

           Setter
                                                                      9
Types of IOC




               10
Types of IOC [Contd.]

   2. Contextualized Dependency Lookup

   public class ContextualizedDependencyLookup
     implements ManagedComponent {
     private Dependency dep;

       public void performLookup(Container container)
       {
           this.dep = (Dependency)container.get
          Dependency("myDependency");
       }

   }

                                                        11
Types of DI

   1. Constructor Dependency

   public class ConstructorInjection {

       private Dependency dep;

       public ConstructorInjection(Dependency dep) {
           this.dep = dep;
       }
   }




                                                       12
Types of IOC [Contd.]

   2. Setter Dependency

   public class SetterInjection {

       private Dependency dep;

       public void setMyDependency(Dependency dep) {
                 this.dep = dep;
       }
   }




                                                       13
Injection Vs Lookup

      Disadvantages of Lookup
          Need to obtain handler of Registry to interact

          Classes are dependent on classes & interfaces of IOC container

          Testing in isolation from container becomes difficult


      Advantages of Injection
          Minimal impact on existing code

          Classes are completely decoupled from IOC container

          Testing becomes much more easier




                                                                            14
Setter Injection Vs Constructor Injection

   




                                            15
Dependency Injection with Spring

      Hello World example - [HelloWorldMainApp]

      Beans & Bean Factories –

      Setter DI example –
       [SetterDependencyInjectionMainApp]

      Constructor DI example – [Main]
          Constructor confusion example – [ConstructorConfusionDemo]




                                                                        16
Injecting Beans




                  17
Injecting bean using Bean Alias




                                  18
Bean Factory Nesting



   BeanFactory parent = new XmlBeanFactory(new
     FileSystemResource("./com/src/conf/parent.xml"));



   BeanFactory child = new XmlBeanFactory(new
     FileSystemResource(
     "./com/src/conf/beans.xml"), parent);




                                                     19
Understanding Bean Naming




                            20
Bean Instantiation Modes

      Singleton

      Non-Singleton




                           21
Bean Instantiation Modes [Contd.]
      Non-Singleton Instantiation Modes
       Mode         Description
       Prototype    Every call to the getBean() method returns a new
                    instance of the bean.
       request      Every call to the getBean() method in a web
                    application will return a unique instance of the
                    bean for every HTTP request. This behavior is only
                    implemented in the WebApplicationContext and its
                    subinterfaces.
       session      Calls to the getBean() method will return a unique
                    instance of the bean for every HTTP Session. Just
                    like request, this scope is only available in
                    WebApplicationContext and its subinterfaces.
       global       The getBean() calls will return a unique instance of
       session      the bean for the global HTTP session in a portlet
                    context. Just like request and session scopes, this
                    instantiation mode is only supported in
                    WebApplicationContext and its subinterfaces. 22
Bean Instantiation Modes [Contd.]

      Choosing an instantiation mode
          Singleton
                   Shared objects with no state
                   Shared objects with read only state
                   Shared objects with shared state
                   High throughput objects with writable state

          Non-Singleton
                   Objects with writable state
                   Objects with private state


   Bean scope example – [ScopeDemo]




                                                                  23
Resolving Dependencies



   <bean id="A"
     class="com.apress.prospring.ch4.BeanA" depends-
     on=“B"/>

   <bean id="B"
     class="com.apress.prospring.ch4.BeanB"/>




                                                       24
Auto wiring your Beans
      Spring supports 4 modes of auto wiring
          byName
          byType
          Constructor
          Autodetect


   Auto wiring example – [AutowiringDemo]

      When to use




                                                25
Checking Dependencies

      Spring has 3 modes for dependency checking
          simple

          object

          all


      Example

   <bean id="simpleBean1"
     class="com.innotech.spring.training.SimpleBean“
     dependency-check="simple">



                                                       26
Bean Inheritance




                   27
Life Cycle of Spring Bean




                            28
Life Cycle of Spring Bean [Contd.]
      BeanFactoryPostProcessor
          Executes after spring has finished constructing BeanFactory but
           before BeanFactory constructs beans
      BeanFactoryPost-Processors of Spring
    Post-                 Description
    Processors
    AspectJWeavingE This post-processor registers AspectJ’s
    nabler          ClassPreProcessorAgentAdapter to be used in
                    Spring’s LoadTimeWeaver

    CustomAutowire        This one allows you to specify annotations, in
    Configurer            addition to @Qualifier, to indicate that a bean is a
                          candidate for automatic wiring.

    CustomEditorCon This registers the PropertyEditor implementations
    figurer         that Spring will use in attempts to convert string
                    values in the configuration files to types required
                    by the beans.
                                                                             29
Life Cycle of Spring Bean [Contd.]
      BeanFactoryPost-Processors of Spring
    Post-          Description
    Processors
    CustomScop     Use this post-processor to configure custom scopes (in
    eConfigurer    addition to singleton, prototype, request, session, and
                   globalSession) in the configuration file. Set the scopes
                   property to a Map containing the scope name as key
                   and the implementation of the Scope interface as value.
    PreferencesP This post-processor will replace the values in beans'
    laceholderCo properties using JDK 1.4’s Preferences API. The
    nfigurer     Preferences API states that it will try to resolve a value
                 first from user preferences (Preferences.userRoot()),
                 then system preferences (Preferences.systemRoot()),
                 and finally from a preferences file.
    PropertyPlac   This post-processor will replace values of properties
    eholderConfi   with values loaded from the configured properties file, if
    gurer          the values follow certain formatting rules (by default, $
                   {property-name}).                                   30
Life Cycle of Spring Bean [Contd.]
      BeanFactoryPost-Processors of Spring
    Post-           Description
    Processors
    PropertyOverr This post-processor will replace values of beans’
    ideConfigurer properties from values loaded from the specified
                  properties file. It will search the properties file for a
                  property constructed from the bean name and
                  property: for property a of bean x, it will look for x.a in
                  the properties file. If the property does not exist, the
                  post-processor will leave the value found in the
                  configuration file.
    ServletContex   This post-processor extends
    tPropertyPlac   PropertyPlaceholderConfigurer; therefore, it replaces
    eholderConfig   beans’ properties if they follow the specified naming
    urer            convention. In addition to its superclass, this processor
                    will load values from context-param entries of the
                    servlet that is hosting the application.
                                                                       31
Life Cycle of Spring Bean [Contd.]

      BeanPostProcessor of Spring has 2 methods
          postProcessBeforeInitialization

          postProcessAfterInitialization




   Spring Life Cycle example – [LifeCycleDemo,
     SimpleBeanDemo]




                                                   32
Spring’s ApplicationContext

      Its an interface same as BeanFactory

      ApplicationContext Vs BeanFactory

      Implementation of ApplicationContext
          ClassPathXmlApplicationContext
          FileSystemXmlApplicationContext
          XmlWebApplicationContext




                                              33
Spring’s built-in Property Editors
   Property Editor    Reg. by   Description
                      Default
   ByteArrayPropert      Y      This PropertyEditor converts a String value
   yEditor                      into an array of bytes.
   ClassEditor           Y      The ClassEditor converts from a fully
                                qualified class name into a Class instance.
                                When using this PropertyEditor, be careful
                                not to include any extraneous spaces on
                                either side of the class name when using
                                XmlBeanFactory, because this results in a
                                ClassNotFoundException.
   CustomBooleanEd       N      This customizable editor for Boolean values
   itor                         is intended to be used in UI-centric code,
                                where it can parse different String
                                representations of Boolean values; for
                                example, “Yes”/ “No” or “Ano”/“Ne”.

                                                                     34
Spring’s built-in Property Editors [Contd.]
  Property         Reg. by Description
  Editor           Default

  CustomCollecti     N     This PropertyEditor can be used to create any
  onEditor                 type of the Java Collections framework or an
                           array.
  CustomDateEd       N     Just like the CustomBooleanEditor, this
  itor                     PropertyEditor is typically used in the
                           controller’s initBinder method to enable the
                           application to parse dates entered in a
                           localespecific format to a java.util.Date.
  FileEditor         Y     The FileEditor converts a String file path into a
                           File instance. Spring does not check to see if
                           the file (or directory) exists.
  CustomNumbe        N     This PropertyEditor converts a String into an
  rEditor                  Integer, a Long, a BigDecimal, or any other
                           Number subclass.
                                                                       35
Spring’s built-in Property Editors [Contd.]
   Property        Reg. by   Description
   Editor          Default
   LocaleEditor       Y      The LocaleEditor converts the String
                             representation of a locale, such as en-GB, into
                             a java.util.Locale instance.
   PatternEditor      Y      This ResourceEditor converts a regular
                             expression (passed in as a String) into a
                             java.util.regex.Pattern instance.
   StringTrimme       N      The StringTrimmerEditor can be used to trim
   rEditor                   nonempty Strings and to transform each
                             empty String into null.
   InputStreamE       Y      This editor will convert a String into an
   ditor                     InputStream. Note that this PropertyEditor is a
                             not reflective; it can only convert String to
                             InputStream, not the other way around.
                             Internally, the conversion is achieved by
                             instantiating a temporary ResourceEditor for a
                             Resource.                                36
Spring’s built-in Property Editors [Contd.]


  Property         Reg. by   Description
  Editor           Default
  PropertiesEdit      Y      PropertiesEditor converts a String in the
  or                         format key1=value1n key2=value2n
                             keyn=valuen into an instance of java.util.
                             Properties with the corresponding properties
                             configured.
  StringArrayPr       Y      The StringArrayPropertyEditor class converts a
  opertyEditor               comma-separated list of String elements into a
                             String array.
  URLEditor           N      The URLEditor converts a String representation
                             of a URL into an instance of java.net.URL.



                                                                       37
SPRING AOP




             38
Spring AOP

      AOP background




                        39
Spring AOP [Contd.]
      AOP Concepts
          Aspect
          Advice
          JoinPoint
          PointCut
          Target
          Introduction
          Proxy
          Weaving
               Compile time
               Classload time
               Runtime



      Types of AOP
          Static AOP
          Dynamic AOP


                                 40
Types of Advice


        Advice Name       Interface
        Before            org.springframework.aop.Meth
                          odBeforeAdvice
        After Returning   org.springframework.aop.After
                          ReturningAdvice
        Around            org.aopalliance.intercept.Metho
                          dInterceptor
        Throws            org.springframework.
                          aop.ThrowsAdvice
        Introduction      org.springframework.aop.
                          IntroductionInterceptor




                                                            41
The Pointcut Interface
    public interface Pointcut {
      ClassFilter getClassFilter ();
      MethodMatcher getMethodMatcher();
    }

    public interface ClassFilter{
      boolean matches(Class clazz);
    }

    public interface MethodMatcher{
      boolean matches(Method m, Class targetClass);
      boolean isRuntime();
      boolean matches(Method m, Class targetClass,
          Object[] args);
                                                      42
    }
Types of Pointcut
 Implementation     Description
 Class
 org.springframewo The ComposablePointcut class is used to compose two
 rk.aop.support.Co or more pointcuts together with operations such as
 mposablePointcut union() and intersection().
 org.springframewo The ControlFlowPointcut is a special case pointcut that
 rk.aop.support.Co matches all methods within the control flow of
 ntrolFlowPointcut another method, that is, any method that is invoked
                   either directly or indirectly as the result of another
                   method being invoked.
 org.springframewo The JdkRexepMethodPointcut allows you to define
 rk.aop.support.Jdk pointcuts using JDK 1.4 regular expression support.
 RegexpMethodPoin This class requires JDK 1.4 or higher.
 tcut
 org.springframewo The AnnotationMatchingPointcut class is used for
 rk.aop.Annotation creating Java 5 annotated pointcuts.
 MatchingPointcut
                                                                      43
Types of Pointcut [Contd.]
 Implementation       Description
 Class
 org.springframework Using the NameMatchMethodPointcut, you can
 .aop.support.NameM create a pointcut that performs simple matching
 atchMethodPointcut against a list of method names.
 org.springframework The StaticMethodMatcherPointcut class is intended
 .aop.StaticMethodM as a base for building static pointcuts.
 atcherPointcut
 org.springframework The DynamicMethodMatcherPointcut class is a
 .aop.DynamicMetho convenient superclass for building dynamic
 dMatcherPointcut    pointcuts that are aware of method arguments at
                     runtime.
 org.springframework The AspectJExpressionPointcut convenient class is
 .aop.AspectJExpressi used for defining pointcuts using AspectJ expression
 onPointcut           language. Note that only method execution
                      pointcuts can be defined, as Spring AOP does not
                      support other AspectJ pointcuts in the current
                      version.                                        44
SPRING - JDBC




                45
Concepts in Spring Data Access Support
      Understanding Spring’s DataAccessException
          You are not forced to handle DataAccessException
          Spring classifies exception for you




                                                              46
Concepts in Spring Data Access Support [Contd.]
 Exception              Description
 CleanupFailureDataA An operation completes successfully, but an
 ccessException      exception occurs while cleaning up database
                     resources (e.g., closing a Connection).
 DataAccessResource     A data access resource fails completely, such as not
 FailureException       being able to connect to a database.
 DataIntegrityViolatio An insert or update results in an integrity violation,
 nException            such as a violation of a unique constraint.
 DataRetrievalFailure   Certain data could not be retrieved, such as not
 Exception              finding a row by primary key.
 DeadlockLoserDataA The current process was a deadlock loser.
 ccessException
 IncorrectUpdateSem When something unintended happens on an update,
 anticsData-        such as updating more rows than expected. When
 AccessException    this exception is thrown, the operation’s transaction
                    has not been rolled back.
                                                                         47
Concepts in Spring Data Access Support [Contd.]
 Exception              Description
 InvalidDataAccessAp A data access Java API is used incorrectly, such as
 iUsageException     failing to compile a query that must be compiled
                     before execution.
 InvalidDataAccessRe A data access resource is used incorrectly, such as
 sourceUsage         using bad SQL grammar to access a relational
 Exception           database.
 OptimisticLockingFai   There is an optimistic locking failure. This will be
 lureException          thrown by ORM tools or by custom DAO
                        implementations.
 TypeMismatchDataA      There is a mismatch between Java type and data
 ccessException         type, such as trying to insert a String into a
                        numeric database column.
 UncategorizedDataA     Something goes wrong, but a more specific
 ccessException         exception cannot be determined.


                                                                          48
JDBC Data Access Support
      Using JDBCTemplate




                            49
JDBC Data Access Support [Contd.]
      Operations of JDBCTemplate
          JdbcTemplate.execute
          JdbcTemplate.query
          JdbcTemplate.update
          JdbcTemplate.batchUpdate




                                      50
JdbcDaoSupport




                 51
SPRING - TRANSACTION




                       52
Spring Transaction

      What is TRANSACTION?

      Types of Transaction
          Local Transaction
          Global Transaction


      Properties of Transaction
          Atomicity
          Consistency
          Isolation
          Durability




                                   53
TransactionDefinition interface


   public interface TransactionDefinition {
     int getPropagationBehavior();
     int getIsolationLevel();
     int getTimeout();
     boolean isReadOnly();
   }




                                              54
Spring’s Transaction Isolation levels
 Isolation Level   Description
 ISOLATION_DEF     Use the default isolation level of the underlying data-
 AULT              store.
 ISOLATION_REA     Allows you to read changes that have not yet been
 D_UNCOMMITTE      committed. May result in dirty reads, phantom reads,
 D                 and non-repeatable reads.
 ISOLATION_REA     Allows reads from concurrent transactions that have
 D_COMMITTED       been committed. Dirty reads are prevented, but
                   phantom and non-repeatable reads may still occur.
 ISOLATION_REP     Multiple reads of the same field will yield the same
 EATABLE_READ      results, unless changed by the transaction itself. Dirty
                   reads and non-repeatable reads are prevented by
                   phantom reads may still occur.
 ISOLATION_SERI This fully ACID-compliant isolation level ensures that
 ALIZABLE       dirty reads, non-repeatable reads, and phantom reads
                are all prevented. This is the slowest of all isolation
                levels because it is typically accomplished by doing full
                table locks on the tables involved in the transaction.
                                                                     55
Spring’s Transaction Propagation Behavior

    Propagation   What does it mean
    Behavior
    PROPAGATION   Spring will use an active transaction if it exists. If
    _REQUIRED     not, Spring will begin a new transaction.
    PROPAGATION   Spring will use an active transaction; if there is
    _SUPPORTS     no active transaction, Spring will not start a new
                  one.
    PROPAGATION   Spring will use an active transaction; if there is
    _MANDATORY    no active transaction, Spring will throw an
                  exception.
    PROPAGATION   Spring will always start a new transaction. If an
    _REQUIRES_N   active transaction already exists, it is suspended.
    EW



                                                                       56
Spring’s Transaction Propagation Behavior [Contd.]
    Propagation   What does it mean
    Behavior
    PROPAGATION Spring will not execute the code in an active
    _NOT_SUPPOR transaction. The code always executes non-
    TED         transactionally and suspends any existing
                transaction.
    PROPAGATION   This always executes nontransactionally even if
    _NEVER        an active transaction exists. It throws an
                  exception if an active transaction exists.
    PROPAGATION   This runs in a nested transaction if an active
    _NESTED       Transaction exists. If there is no active
                  transaction, the code runs as if
                  TransactionDefinition.PROPAGATION_REQUIRED
                  is set.




                                                                    57
Left overs’ !


     Spring - Hibernate
     Spring - Webservice
     Spring schedulers
     Spring email
     Spring MVC
     Spring – UnitTesting/TDD
     ....
     ...
     ..
     List goes on & on . . . :D



                                   58
Questions?




             59
Resources/References


      Spring – www.springframework.org

      Inversion of Control -
       http://www.martinfowler.com/articles/injection.html

      Spring in Action – Walls, Breidenbach




                                                             60
Personal Information


  E-mail   : shah_d_p@yahoo.com




           : http://twitter.com/dhaval201279




           : http://in.linkedin.com/in/dhavalshah201279



                                                          61

More Related Content

What's hot

Spring IOC advantages and developing spring application sample
Spring IOC advantages and developing spring application sample Spring IOC advantages and developing spring application sample
Spring IOC advantages and developing spring application sample Sunil kumar Mohanty
 
Using Contexts & Dependency Injection in the Java EE 6 Platform
Using Contexts & Dependency Injection in the Java EE 6 PlatformUsing Contexts & Dependency Injection in the Java EE 6 Platform
Using Contexts & Dependency Injection in the Java EE 6 PlatformArun Gupta
 
Contexts and Dependency Injection for the JavaEE platform
Contexts and Dependency Injection for the JavaEE platformContexts and Dependency Injection for the JavaEE platform
Contexts and Dependency Injection for the JavaEE platformBozhidar Bozhanov
 
02 java spring-hibernate-experience-questions
02 java spring-hibernate-experience-questions02 java spring-hibernate-experience-questions
02 java spring-hibernate-experience-questionsDhiraj Champawat
 
02.egovFrame Development Environment workshop I
02.egovFrame  Development Environment workshop I02.egovFrame  Development Environment workshop I
02.egovFrame Development Environment workshop IChuong Nguyen
 
Enterprise Java Beans 3 - Business Logic
Enterprise Java Beans 3 - Business LogicEnterprise Java Beans 3 - Business Logic
Enterprise Java Beans 3 - Business LogicEmprovise
 
02. egovFrame Development Environment workshop II en(nexus&ci)
02. egovFrame Development Environment workshop II en(nexus&ci)02. egovFrame Development Environment workshop II en(nexus&ci)
02. egovFrame Development Environment workshop II en(nexus&ci)Chuong Nguyen
 
Spring talk111204
Spring talk111204Spring talk111204
Spring talk111204s4al_com
 
Ejb 2.0
Ejb 2.0Ejb 2.0
Ejb 2.0sukace
 
Enterprise java beans(ejb) update 2
Enterprise java beans(ejb) update 2Enterprise java beans(ejb) update 2
Enterprise java beans(ejb) update 2vikram singh
 
Enterprise java beans(ejb)
Enterprise java beans(ejb)Enterprise java beans(ejb)
Enterprise java beans(ejb)vikram singh
 
Contextual Dependency Injection for Apachecon 2010
Contextual Dependency Injection for Apachecon 2010Contextual Dependency Injection for Apachecon 2010
Contextual Dependency Injection for Apachecon 2010Rohit Kelapure
 
Java EE 與 雲端運算的展望
Java EE 與 雲端運算的展望 Java EE 與 雲端運算的展望
Java EE 與 雲端運算的展望 javatwo2011
 
EJB3 Advance Features
EJB3 Advance FeaturesEJB3 Advance Features
EJB3 Advance FeaturesEmprovise
 

What's hot (20)

Spring IOC advantages and developing spring application sample
Spring IOC advantages and developing spring application sample Spring IOC advantages and developing spring application sample
Spring IOC advantages and developing spring application sample
 
Using Contexts & Dependency Injection in the Java EE 6 Platform
Using Contexts & Dependency Injection in the Java EE 6 PlatformUsing Contexts & Dependency Injection in the Java EE 6 Platform
Using Contexts & Dependency Injection in the Java EE 6 Platform
 
Contexts and Dependency Injection for the JavaEE platform
Contexts and Dependency Injection for the JavaEE platformContexts and Dependency Injection for the JavaEE platform
Contexts and Dependency Injection for the JavaEE platform
 
EJB .
EJB .EJB .
EJB .
 
02 java spring-hibernate-experience-questions
02 java spring-hibernate-experience-questions02 java spring-hibernate-experience-questions
02 java spring-hibernate-experience-questions
 
02.egovFrame Development Environment workshop I
02.egovFrame  Development Environment workshop I02.egovFrame  Development Environment workshop I
02.egovFrame Development Environment workshop I
 
Spring by rj
Spring by rjSpring by rj
Spring by rj
 
Enterprise Java Beans 3 - Business Logic
Enterprise Java Beans 3 - Business LogicEnterprise Java Beans 3 - Business Logic
Enterprise Java Beans 3 - Business Logic
 
Javabeans .pdf
Javabeans .pdfJavabeans .pdf
Javabeans .pdf
 
02. egovFrame Development Environment workshop II en(nexus&ci)
02. egovFrame Development Environment workshop II en(nexus&ci)02. egovFrame Development Environment workshop II en(nexus&ci)
02. egovFrame Development Environment workshop II en(nexus&ci)
 
Spring
SpringSpring
Spring
 
Spring talk111204
Spring talk111204Spring talk111204
Spring talk111204
 
Ejb 2.0
Ejb 2.0Ejb 2.0
Ejb 2.0
 
Enterprise java beans(ejb) update 2
Enterprise java beans(ejb) update 2Enterprise java beans(ejb) update 2
Enterprise java beans(ejb) update 2
 
Enterprise java beans(ejb)
Enterprise java beans(ejb)Enterprise java beans(ejb)
Enterprise java beans(ejb)
 
Contextual Dependency Injection for Apachecon 2010
Contextual Dependency Injection for Apachecon 2010Contextual Dependency Injection for Apachecon 2010
Contextual Dependency Injection for Apachecon 2010
 
Java EE 與 雲端運算的展望
Java EE 與 雲端運算的展望 Java EE 與 雲端運算的展望
Java EE 與 雲端運算的展望
 
Java beans
Java beansJava beans
Java beans
 
Ejb3 Presentation
Ejb3 PresentationEjb3 Presentation
Ejb3 Presentation
 
EJB3 Advance Features
EJB3 Advance FeaturesEJB3 Advance Features
EJB3 Advance Features
 

Viewers also liked

The scope of environmental problem
The scope of environmental problemThe scope of environmental problem
The scope of environmental problembiancasisonsiriban
 
Ipod touches in the classroom
Ipod touches in the classroomIpod touches in the classroom
Ipod touches in the classroommissiedavis
 
互联网产品经理向传统产品经理借鉴什么 阿光
互联网产品经理向传统产品经理借鉴什么 阿光互联网产品经理向传统产品经理借鉴什么 阿光
互联网产品经理向传统产品经理借鉴什么 阿光yixieshi
 
InvestinBelgium2011
InvestinBelgium2011InvestinBelgium2011
InvestinBelgium2011bdeelen
 
ViM People - Internal Support
ViM People - Internal SupportViM People - Internal Support
ViM People - Internal SupportViMPeople
 
Group Weibo Account Analysis
Group Weibo Account AnalysisGroup Weibo Account Analysis
Group Weibo Account AnalysisYixuan Yang
 
2012 04 24prezentacja-szkoly
2012 04 24prezentacja-szkoly2012 04 24prezentacja-szkoly
2012 04 24prezentacja-szkolysp11bialystok
 
организация внеурочной деятельности
организация внеурочной деятельностиорганизация внеурочной деятельности
организация внеурочной деятельностиgustenjova
 
萬寿鏡 甕覗(ますかがみ かめのぞき)
萬寿鏡 甕覗(ますかがみ かめのぞき)萬寿鏡 甕覗(ますかがみ かめのぞき)
萬寿鏡 甕覗(ますかがみ かめのぞき)Megumi Yamazaki
 
Mitos em Nutrição
Mitos em NutriçãoMitos em Nutrição
Mitos em Nutriçãonutriscience
 

Viewers also liked (20)

Republika srbija
Republika srbijaRepublika srbija
Republika srbija
 
The scope of environmental problem
The scope of environmental problemThe scope of environmental problem
The scope of environmental problem
 
Ipod touches in the classroom
Ipod touches in the classroomIpod touches in the classroom
Ipod touches in the classroom
 
互联网产品经理向传统产品经理借鉴什么 阿光
互联网产品经理向传统产品经理借鉴什么 阿光互联网产品经理向传统产品经理借鉴什么 阿光
互联网产品经理向传统产品经理借鉴什么 阿光
 
InvestinBelgium2011
InvestinBelgium2011InvestinBelgium2011
InvestinBelgium2011
 
ViM People - Internal Support
ViM People - Internal SupportViM People - Internal Support
ViM People - Internal Support
 
Group Weibo Account Analysis
Group Weibo Account AnalysisGroup Weibo Account Analysis
Group Weibo Account Analysis
 
2012 04 24prezentacja-szkoly
2012 04 24prezentacja-szkoly2012 04 24prezentacja-szkoly
2012 04 24prezentacja-szkoly
 
организация внеурочной деятельности
организация внеурочной деятельностиорганизация внеурочной деятельности
организация внеурочной деятельности
 
Digital
DigitalDigital
Digital
 
6
66
6
 
Tp tajuk4
Tp tajuk4Tp tajuk4
Tp tajuk4
 
萬寿鏡 甕覗(ますかがみ かめのぞき)
萬寿鏡 甕覗(ますかがみ かめのぞき)萬寿鏡 甕覗(ますかがみ かめのぞき)
萬寿鏡 甕覗(ますかがみ かめのぞき)
 
France and Vietnam
France and VietnamFrance and Vietnam
France and Vietnam
 
Online education
Online educationOnline education
Online education
 
Jonas biliunas
Jonas biliunasJonas biliunas
Jonas biliunas
 
Catalogo
CatalogoCatalogo
Catalogo
 
Bluetooth
BluetoothBluetooth
Bluetooth
 
выпуск 9
выпуск 9выпуск 9
выпуск 9
 
Mitos em Nutrição
Mitos em NutriçãoMitos em Nutrição
Mitos em Nutrição
 

Similar to Spring training

Spring introduction
Spring introductionSpring introduction
Spring introductionLê Hảo
 
Spring - Part 1 - IoC, Di and Beans
Spring - Part 1 - IoC, Di and Beans Spring - Part 1 - IoC, Di and Beans
Spring - Part 1 - IoC, Di and Beans Hitesh-Java
 
Session 43 - Spring - Part 1 - IoC DI Beans
Session 43 - Spring - Part 1 - IoC DI BeansSession 43 - Spring - Part 1 - IoC DI Beans
Session 43 - Spring - Part 1 - IoC DI BeansPawanMM
 
Introduction to Spring Framework
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring FrameworkRajind Ruparathna
 
Spring IOC and DAO
Spring IOC and DAOSpring IOC and DAO
Spring IOC and DAOAnushaNaidu
 
2-0. Spring ecosytem.pdf
2-0. Spring ecosytem.pdf2-0. Spring ecosytem.pdf
2-0. Spring ecosytem.pdfDeoDuaNaoHet
 
Java Spring framework, Dependency Injection, DI, IoC, Inversion of Control
Java Spring framework, Dependency Injection, DI, IoC, Inversion of ControlJava Spring framework, Dependency Injection, DI, IoC, Inversion of Control
Java Spring framework, Dependency Injection, DI, IoC, Inversion of ControlArjun Thakur
 
Skillwise-Spring framework 1
Skillwise-Spring framework 1Skillwise-Spring framework 1
Skillwise-Spring framework 1Skillwise Group
 
Spring framework in depth
Spring framework in depthSpring framework in depth
Spring framework in depthVinay Kumar
 
Spring Fa Qs
Spring Fa QsSpring Fa Qs
Spring Fa Qsjbashask
 
CommercialSystemsBahman.ppt
CommercialSystemsBahman.pptCommercialSystemsBahman.ppt
CommercialSystemsBahman.pptKalsoomTahir2
 
Spring training
Spring trainingSpring training
Spring trainingTechFerry
 
Spring from a to Z
Spring from  a to ZSpring from  a to Z
Spring from a to Zsang nguyen
 
Introduction to Spring Framework
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring FrameworkDineesha Suraweera
 
Spring 3.1: a Walking Tour
Spring 3.1: a Walking TourSpring 3.1: a Walking Tour
Spring 3.1: a Walking TourJoshua Long
 

Similar to Spring training (20)

Spring framework
Spring frameworkSpring framework
Spring framework
 
Spring introduction
Spring introductionSpring introduction
Spring introduction
 
Spring - Part 1 - IoC, Di and Beans
Spring - Part 1 - IoC, Di and Beans Spring - Part 1 - IoC, Di and Beans
Spring - Part 1 - IoC, Di and Beans
 
Session 43 - Spring - Part 1 - IoC DI Beans
Session 43 - Spring - Part 1 - IoC DI BeansSession 43 - Spring - Part 1 - IoC DI Beans
Session 43 - Spring - Part 1 - IoC DI Beans
 
Introduction to Spring Framework
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring Framework
 
Spring IOC and DAO
Spring IOC and DAOSpring IOC and DAO
Spring IOC and DAO
 
2-0. Spring ecosytem.pdf
2-0. Spring ecosytem.pdf2-0. Spring ecosytem.pdf
2-0. Spring ecosytem.pdf
 
Java Spring framework, Dependency Injection, DI, IoC, Inversion of Control
Java Spring framework, Dependency Injection, DI, IoC, Inversion of ControlJava Spring framework, Dependency Injection, DI, IoC, Inversion of Control
Java Spring framework, Dependency Injection, DI, IoC, Inversion of Control
 
Spring Basics
Spring BasicsSpring Basics
Spring Basics
 
Skillwise-Spring framework 1
Skillwise-Spring framework 1Skillwise-Spring framework 1
Skillwise-Spring framework 1
 
Spring framework in depth
Spring framework in depthSpring framework in depth
Spring framework in depth
 
Spring Fa Qs
Spring Fa QsSpring Fa Qs
Spring Fa Qs
 
CommercialSystemsBahman.ppt
CommercialSystemsBahman.pptCommercialSystemsBahman.ppt
CommercialSystemsBahman.ppt
 
Spring training
Spring trainingSpring training
Spring training
 
Spring from a to Z
Spring from  a to ZSpring from  a to Z
Spring from a to Z
 
Spring core
Spring coreSpring core
Spring core
 
Introduction to Spring Framework
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring Framework
 
Spring framework
Spring frameworkSpring framework
Spring framework
 
Spring 3.1: a Walking Tour
Spring 3.1: a Walking TourSpring 3.1: a Walking Tour
Spring 3.1: a Walking Tour
 
Spring Framework
Spring FrameworkSpring Framework
Spring Framework
 

Recently uploaded

Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 

Recently uploaded (20)

Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 

Spring training

  • 1. Spring 2.5 Framework Dhaval P. Shah 1
  • 2. My Introduction  6.5+ years of experience in developing/supporting enterprise applications  SCJP 1.4  SCWCD 1.4 2
  • 3. Agenda  Spring Jump start  Core Spring  Spring AOP  Spring JDBC  Spring Transaction 3
  • 4. Pre-requisites  Core Java  JDBC  JNDI  Basic usage of IDE 4
  • 5. What this training is not -  An expert in Spring  Having detailed discussion on all the topics of Spring 5
  • 6. Spring jump start  Why Spring?  Spring overview  Lightweight  IOC  Aspect Oriented  Container  Framework 6
  • 7. Spring jump start [Contd.]  Spring Modules  Spring overview  Lightweight  IOC  Aspect Oriented  Container  Framework 7
  • 9. DI / IoC  Brief history about DI  Dependency Inversion: Precursor to Dependency Injection  What is DI?  DI Vs IOC  Types of IOC  Dependency Pull  Contextualized Dependency Lookup (CDL)  Types of DI  Constructor  Setter 9
  • 11. Types of IOC [Contd.] 2. Contextualized Dependency Lookup public class ContextualizedDependencyLookup implements ManagedComponent { private Dependency dep; public void performLookup(Container container) { this.dep = (Dependency)container.get Dependency("myDependency"); } } 11
  • 12. Types of DI 1. Constructor Dependency public class ConstructorInjection { private Dependency dep; public ConstructorInjection(Dependency dep) { this.dep = dep; } } 12
  • 13. Types of IOC [Contd.] 2. Setter Dependency public class SetterInjection { private Dependency dep; public void setMyDependency(Dependency dep) { this.dep = dep; } } 13
  • 14. Injection Vs Lookup  Disadvantages of Lookup  Need to obtain handler of Registry to interact  Classes are dependent on classes & interfaces of IOC container  Testing in isolation from container becomes difficult  Advantages of Injection  Minimal impact on existing code  Classes are completely decoupled from IOC container  Testing becomes much more easier 14
  • 15. Setter Injection Vs Constructor Injection  15
  • 16. Dependency Injection with Spring  Hello World example - [HelloWorldMainApp]  Beans & Bean Factories –  Setter DI example – [SetterDependencyInjectionMainApp]  Constructor DI example – [Main]  Constructor confusion example – [ConstructorConfusionDemo] 16
  • 18. Injecting bean using Bean Alias 18
  • 19. Bean Factory Nesting BeanFactory parent = new XmlBeanFactory(new FileSystemResource("./com/src/conf/parent.xml")); BeanFactory child = new XmlBeanFactory(new FileSystemResource( "./com/src/conf/beans.xml"), parent); 19
  • 21. Bean Instantiation Modes  Singleton  Non-Singleton 21
  • 22. Bean Instantiation Modes [Contd.]  Non-Singleton Instantiation Modes Mode Description Prototype Every call to the getBean() method returns a new instance of the bean. request Every call to the getBean() method in a web application will return a unique instance of the bean for every HTTP request. This behavior is only implemented in the WebApplicationContext and its subinterfaces. session Calls to the getBean() method will return a unique instance of the bean for every HTTP Session. Just like request, this scope is only available in WebApplicationContext and its subinterfaces. global The getBean() calls will return a unique instance of session the bean for the global HTTP session in a portlet context. Just like request and session scopes, this instantiation mode is only supported in WebApplicationContext and its subinterfaces. 22
  • 23. Bean Instantiation Modes [Contd.]  Choosing an instantiation mode  Singleton  Shared objects with no state  Shared objects with read only state  Shared objects with shared state  High throughput objects with writable state  Non-Singleton  Objects with writable state  Objects with private state Bean scope example – [ScopeDemo] 23
  • 24. Resolving Dependencies <bean id="A" class="com.apress.prospring.ch4.BeanA" depends- on=“B"/> <bean id="B" class="com.apress.prospring.ch4.BeanB"/> 24
  • 25. Auto wiring your Beans  Spring supports 4 modes of auto wiring  byName  byType  Constructor  Autodetect Auto wiring example – [AutowiringDemo]  When to use 25
  • 26. Checking Dependencies  Spring has 3 modes for dependency checking  simple  object  all  Example <bean id="simpleBean1" class="com.innotech.spring.training.SimpleBean“ dependency-check="simple"> 26
  • 28. Life Cycle of Spring Bean 28
  • 29. Life Cycle of Spring Bean [Contd.]  BeanFactoryPostProcessor  Executes after spring has finished constructing BeanFactory but before BeanFactory constructs beans  BeanFactoryPost-Processors of Spring Post- Description Processors AspectJWeavingE This post-processor registers AspectJ’s nabler ClassPreProcessorAgentAdapter to be used in Spring’s LoadTimeWeaver CustomAutowire This one allows you to specify annotations, in Configurer addition to @Qualifier, to indicate that a bean is a candidate for automatic wiring. CustomEditorCon This registers the PropertyEditor implementations figurer that Spring will use in attempts to convert string values in the configuration files to types required by the beans. 29
  • 30. Life Cycle of Spring Bean [Contd.]  BeanFactoryPost-Processors of Spring Post- Description Processors CustomScop Use this post-processor to configure custom scopes (in eConfigurer addition to singleton, prototype, request, session, and globalSession) in the configuration file. Set the scopes property to a Map containing the scope name as key and the implementation of the Scope interface as value. PreferencesP This post-processor will replace the values in beans' laceholderCo properties using JDK 1.4’s Preferences API. The nfigurer Preferences API states that it will try to resolve a value first from user preferences (Preferences.userRoot()), then system preferences (Preferences.systemRoot()), and finally from a preferences file. PropertyPlac This post-processor will replace values of properties eholderConfi with values loaded from the configured properties file, if gurer the values follow certain formatting rules (by default, $ {property-name}). 30
  • 31. Life Cycle of Spring Bean [Contd.]  BeanFactoryPost-Processors of Spring Post- Description Processors PropertyOverr This post-processor will replace values of beans’ ideConfigurer properties from values loaded from the specified properties file. It will search the properties file for a property constructed from the bean name and property: for property a of bean x, it will look for x.a in the properties file. If the property does not exist, the post-processor will leave the value found in the configuration file. ServletContex This post-processor extends tPropertyPlac PropertyPlaceholderConfigurer; therefore, it replaces eholderConfig beans’ properties if they follow the specified naming urer convention. In addition to its superclass, this processor will load values from context-param entries of the servlet that is hosting the application. 31
  • 32. Life Cycle of Spring Bean [Contd.]  BeanPostProcessor of Spring has 2 methods  postProcessBeforeInitialization  postProcessAfterInitialization Spring Life Cycle example – [LifeCycleDemo, SimpleBeanDemo] 32
  • 33. Spring’s ApplicationContext  Its an interface same as BeanFactory  ApplicationContext Vs BeanFactory  Implementation of ApplicationContext  ClassPathXmlApplicationContext  FileSystemXmlApplicationContext  XmlWebApplicationContext 33
  • 34. Spring’s built-in Property Editors Property Editor Reg. by Description Default ByteArrayPropert Y This PropertyEditor converts a String value yEditor into an array of bytes. ClassEditor Y The ClassEditor converts from a fully qualified class name into a Class instance. When using this PropertyEditor, be careful not to include any extraneous spaces on either side of the class name when using XmlBeanFactory, because this results in a ClassNotFoundException. CustomBooleanEd N This customizable editor for Boolean values itor is intended to be used in UI-centric code, where it can parse different String representations of Boolean values; for example, “Yes”/ “No” or “Ano”/“Ne”. 34
  • 35. Spring’s built-in Property Editors [Contd.] Property Reg. by Description Editor Default CustomCollecti N This PropertyEditor can be used to create any onEditor type of the Java Collections framework or an array. CustomDateEd N Just like the CustomBooleanEditor, this itor PropertyEditor is typically used in the controller’s initBinder method to enable the application to parse dates entered in a localespecific format to a java.util.Date. FileEditor Y The FileEditor converts a String file path into a File instance. Spring does not check to see if the file (or directory) exists. CustomNumbe N This PropertyEditor converts a String into an rEditor Integer, a Long, a BigDecimal, or any other Number subclass. 35
  • 36. Spring’s built-in Property Editors [Contd.] Property Reg. by Description Editor Default LocaleEditor Y The LocaleEditor converts the String representation of a locale, such as en-GB, into a java.util.Locale instance. PatternEditor Y This ResourceEditor converts a regular expression (passed in as a String) into a java.util.regex.Pattern instance. StringTrimme N The StringTrimmerEditor can be used to trim rEditor nonempty Strings and to transform each empty String into null. InputStreamE Y This editor will convert a String into an ditor InputStream. Note that this PropertyEditor is a not reflective; it can only convert String to InputStream, not the other way around. Internally, the conversion is achieved by instantiating a temporary ResourceEditor for a Resource. 36
  • 37. Spring’s built-in Property Editors [Contd.] Property Reg. by Description Editor Default PropertiesEdit Y PropertiesEditor converts a String in the or format key1=value1n key2=value2n keyn=valuen into an instance of java.util. Properties with the corresponding properties configured. StringArrayPr Y The StringArrayPropertyEditor class converts a opertyEditor comma-separated list of String elements into a String array. URLEditor N The URLEditor converts a String representation of a URL into an instance of java.net.URL. 37
  • 39. Spring AOP  AOP background 39
  • 40. Spring AOP [Contd.]  AOP Concepts  Aspect  Advice  JoinPoint  PointCut  Target  Introduction  Proxy  Weaving  Compile time  Classload time  Runtime  Types of AOP  Static AOP  Dynamic AOP 40
  • 41. Types of Advice Advice Name Interface Before org.springframework.aop.Meth odBeforeAdvice After Returning org.springframework.aop.After ReturningAdvice Around org.aopalliance.intercept.Metho dInterceptor Throws org.springframework. aop.ThrowsAdvice Introduction org.springframework.aop. IntroductionInterceptor 41
  • 42. The Pointcut Interface public interface Pointcut { ClassFilter getClassFilter (); MethodMatcher getMethodMatcher(); } public interface ClassFilter{ boolean matches(Class clazz); } public interface MethodMatcher{ boolean matches(Method m, Class targetClass); boolean isRuntime(); boolean matches(Method m, Class targetClass, Object[] args); 42 }
  • 43. Types of Pointcut Implementation Description Class org.springframewo The ComposablePointcut class is used to compose two rk.aop.support.Co or more pointcuts together with operations such as mposablePointcut union() and intersection(). org.springframewo The ControlFlowPointcut is a special case pointcut that rk.aop.support.Co matches all methods within the control flow of ntrolFlowPointcut another method, that is, any method that is invoked either directly or indirectly as the result of another method being invoked. org.springframewo The JdkRexepMethodPointcut allows you to define rk.aop.support.Jdk pointcuts using JDK 1.4 regular expression support. RegexpMethodPoin This class requires JDK 1.4 or higher. tcut org.springframewo The AnnotationMatchingPointcut class is used for rk.aop.Annotation creating Java 5 annotated pointcuts. MatchingPointcut 43
  • 44. Types of Pointcut [Contd.] Implementation Description Class org.springframework Using the NameMatchMethodPointcut, you can .aop.support.NameM create a pointcut that performs simple matching atchMethodPointcut against a list of method names. org.springframework The StaticMethodMatcherPointcut class is intended .aop.StaticMethodM as a base for building static pointcuts. atcherPointcut org.springframework The DynamicMethodMatcherPointcut class is a .aop.DynamicMetho convenient superclass for building dynamic dMatcherPointcut pointcuts that are aware of method arguments at runtime. org.springframework The AspectJExpressionPointcut convenient class is .aop.AspectJExpressi used for defining pointcuts using AspectJ expression onPointcut language. Note that only method execution pointcuts can be defined, as Spring AOP does not support other AspectJ pointcuts in the current version. 44
  • 46. Concepts in Spring Data Access Support  Understanding Spring’s DataAccessException  You are not forced to handle DataAccessException  Spring classifies exception for you 46
  • 47. Concepts in Spring Data Access Support [Contd.] Exception Description CleanupFailureDataA An operation completes successfully, but an ccessException exception occurs while cleaning up database resources (e.g., closing a Connection). DataAccessResource A data access resource fails completely, such as not FailureException being able to connect to a database. DataIntegrityViolatio An insert or update results in an integrity violation, nException such as a violation of a unique constraint. DataRetrievalFailure Certain data could not be retrieved, such as not Exception finding a row by primary key. DeadlockLoserDataA The current process was a deadlock loser. ccessException IncorrectUpdateSem When something unintended happens on an update, anticsData- such as updating more rows than expected. When AccessException this exception is thrown, the operation’s transaction has not been rolled back. 47
  • 48. Concepts in Spring Data Access Support [Contd.] Exception Description InvalidDataAccessAp A data access Java API is used incorrectly, such as iUsageException failing to compile a query that must be compiled before execution. InvalidDataAccessRe A data access resource is used incorrectly, such as sourceUsage using bad SQL grammar to access a relational Exception database. OptimisticLockingFai There is an optimistic locking failure. This will be lureException thrown by ORM tools or by custom DAO implementations. TypeMismatchDataA There is a mismatch between Java type and data ccessException type, such as trying to insert a String into a numeric database column. UncategorizedDataA Something goes wrong, but a more specific ccessException exception cannot be determined. 48
  • 49. JDBC Data Access Support  Using JDBCTemplate 49
  • 50. JDBC Data Access Support [Contd.]  Operations of JDBCTemplate  JdbcTemplate.execute  JdbcTemplate.query  JdbcTemplate.update  JdbcTemplate.batchUpdate 50
  • 53. Spring Transaction  What is TRANSACTION?  Types of Transaction  Local Transaction  Global Transaction  Properties of Transaction  Atomicity  Consistency  Isolation  Durability 53
  • 54. TransactionDefinition interface public interface TransactionDefinition { int getPropagationBehavior(); int getIsolationLevel(); int getTimeout(); boolean isReadOnly(); } 54
  • 55. Spring’s Transaction Isolation levels Isolation Level Description ISOLATION_DEF Use the default isolation level of the underlying data- AULT store. ISOLATION_REA Allows you to read changes that have not yet been D_UNCOMMITTE committed. May result in dirty reads, phantom reads, D and non-repeatable reads. ISOLATION_REA Allows reads from concurrent transactions that have D_COMMITTED been committed. Dirty reads are prevented, but phantom and non-repeatable reads may still occur. ISOLATION_REP Multiple reads of the same field will yield the same EATABLE_READ results, unless changed by the transaction itself. Dirty reads and non-repeatable reads are prevented by phantom reads may still occur. ISOLATION_SERI This fully ACID-compliant isolation level ensures that ALIZABLE dirty reads, non-repeatable reads, and phantom reads are all prevented. This is the slowest of all isolation levels because it is typically accomplished by doing full table locks on the tables involved in the transaction. 55
  • 56. Spring’s Transaction Propagation Behavior Propagation What does it mean Behavior PROPAGATION Spring will use an active transaction if it exists. If _REQUIRED not, Spring will begin a new transaction. PROPAGATION Spring will use an active transaction; if there is _SUPPORTS no active transaction, Spring will not start a new one. PROPAGATION Spring will use an active transaction; if there is _MANDATORY no active transaction, Spring will throw an exception. PROPAGATION Spring will always start a new transaction. If an _REQUIRES_N active transaction already exists, it is suspended. EW 56
  • 57. Spring’s Transaction Propagation Behavior [Contd.] Propagation What does it mean Behavior PROPAGATION Spring will not execute the code in an active _NOT_SUPPOR transaction. The code always executes non- TED transactionally and suspends any existing transaction. PROPAGATION This always executes nontransactionally even if _NEVER an active transaction exists. It throws an exception if an active transaction exists. PROPAGATION This runs in a nested transaction if an active _NESTED Transaction exists. If there is no active transaction, the code runs as if TransactionDefinition.PROPAGATION_REQUIRED is set. 57
  • 58. Left overs’ !  Spring - Hibernate  Spring - Webservice  Spring schedulers  Spring email  Spring MVC  Spring – UnitTesting/TDD  ....  ...  ..  List goes on & on . . . :D 58
  • 60. Resources/References  Spring – www.springframework.org  Inversion of Control - http://www.martinfowler.com/articles/injection.html  Spring in Action – Walls, Breidenbach 60
  • 61. Personal Information E-mail : shah_d_p@yahoo.com : http://twitter.com/dhaval201279 : http://in.linkedin.com/in/dhavalshah201279 61

Editor's Notes

  1. Spring MVC – a single shared controller instance handles a particular request type - controllers, interceptors run in the IoC container - allows multiple DispatcherServlets that can share an “application context” - Interface based not class-based
  2. Spring MVC – a single shared controller instance handles a particular request type - controllers, interceptors run in the IoC container - allows multiple DispatcherServlets that can share an “application context” - Interface based not class-based
  3. Spring MVC – a single shared controller instance handles a particular request type - controllers, interceptors run in the IoC container - allows multiple DispatcherServlets that can share an “application context” - Interface based not class-based
  4. Spring MVC – a single shared controller instance handles a particular request type - controllers, interceptors run in the IoC container - allows multiple DispatcherServlets that can share an “application context” - Interface based not class-based
  5. Spring MVC – a single shared controller instance handles a particular request type - controllers, interceptors run in the IoC container - allows multiple DispatcherServlets that can share an “application context” - Interface based not class-based
  6. Spring MVC – a single shared controller instance handles a particular request type - controllers, interceptors run in the IoC container - allows multiple DispatcherServlets that can share an “application context” - Interface based not class-based
  7. Spring MVC – a single shared controller instance handles a particular request type - controllers, interceptors run in the IoC container - allows multiple DispatcherServlets that can share an “application context” - Interface based not class-based
  8. Spring MVC – a single shared controller instance handles a particular request type - controllers, interceptors run in the IoC container - allows multiple DispatcherServlets that can share an “application context” - Interface based not class-based
  9. Spring MVC – a single shared controller instance handles a particular request type - controllers, interceptors run in the IoC container - allows multiple DispatcherServlets that can share an “application context” - Interface based not class-based
  10. Spring MVC – a single shared controller instance handles a particular request type - controllers, interceptors run in the IoC container - allows multiple DispatcherServlets that can share an “application context” - Interface based not class-based
  11. Spring MVC – a single shared controller instance handles a particular request type - controllers, interceptors run in the IoC container - allows multiple DispatcherServlets that can share an “application context” - Interface based not class-based
  12. Spring MVC – a single shared controller instance handles a particular request type - controllers, interceptors run in the IoC container - allows multiple DispatcherServlets that can share an “application context” - Interface based not class-based
  13. Spring MVC – a single shared controller instance handles a particular request type - controllers, interceptors run in the IoC container - allows multiple DispatcherServlets that can share an “application context” - Interface based not class-based
  14. Spring MVC – a single shared controller instance handles a particular request type - controllers, interceptors run in the IoC container - allows multiple DispatcherServlets that can share an “application context” - Interface based not class-based
  15. Spring MVC – a single shared controller instance handles a particular request type - controllers, interceptors run in the IoC container - allows multiple DispatcherServlets that can share an “application context” - Interface based not class-based
  16. Spring MVC – a single shared controller instance handles a particular request type - controllers, interceptors run in the IoC container - allows multiple DispatcherServlets that can share an “application context” - Interface based not class-based
  17. Spring MVC – a single shared controller instance handles a particular request type - controllers, interceptors run in the IoC container - allows multiple DispatcherServlets that can share an “application context” - Interface based not class-based
  18. Spring MVC – a single shared controller instance handles a particular request type - controllers, interceptors run in the IoC container - allows multiple DispatcherServlets that can share an “application context” - Interface based not class-based
  19. Spring MVC – a single shared controller instance handles a particular request type - controllers, interceptors run in the IoC container - allows multiple DispatcherServlets that can share an “application context” - Interface based not class-based
  20. Spring MVC – a single shared controller instance handles a particular request type - controllers, interceptors run in the IoC container - allows multiple DispatcherServlets that can share an “application context” - Interface based not class-based
  21. Spring MVC – a single shared controller instance handles a particular request type - controllers, interceptors run in the IoC container - allows multiple DispatcherServlets that can share an “application context” - Interface based not class-based
  22. Spring MVC – a single shared controller instance handles a particular request type - controllers, interceptors run in the IoC container - allows multiple DispatcherServlets that can share an “application context” - Interface based not class-based
  23. Spring MVC – a single shared controller instance handles a particular request type - controllers, interceptors run in the IoC container - allows multiple DispatcherServlets that can share an “application context” - Interface based not class-based
  24. Spring MVC – a single shared controller instance handles a particular request type - controllers, interceptors run in the IoC container - allows multiple DispatcherServlets that can share an “application context” - Interface based not class-based
  25. Spring MVC – a single shared controller instance handles a particular request type - controllers, interceptors run in the IoC container - allows multiple DispatcherServlets that can share an “application context” - Interface based not class-based
  26. Spring MVC – a single shared controller instance handles a particular request type - controllers, interceptors run in the IoC container - allows multiple DispatcherServlets that can share an “application context” - Interface based not class-based
  27. Spring MVC – a single shared controller instance handles a particular request type - controllers, interceptors run in the IoC container - allows multiple DispatcherServlets that can share an “application context” - Interface based not class-based
  28. Spring MVC – a single shared controller instance handles a particular request type - controllers, interceptors run in the IoC container - allows multiple DispatcherServlets that can share an “application context” - Interface based not class-based
  29. Spring MVC – a single shared controller instance handles a particular request type - controllers, interceptors run in the IoC container - allows multiple DispatcherServlets that can share an “application context” - Interface based not class-based
  30. Spring MVC – a single shared controller instance handles a particular request type - controllers, interceptors run in the IoC container - allows multiple DispatcherServlets that can share an “application context” - Interface based not class-based
  31. Spring MVC – a single shared controller instance handles a particular request type - controllers, interceptors run in the IoC container - allows multiple DispatcherServlets that can share an “application context” - Interface based not class-based
  32. Spring MVC – a single shared controller instance handles a particular request type - controllers, interceptors run in the IoC container - allows multiple DispatcherServlets that can share an “application context” - Interface based not class-based
  33. Spring MVC – a single shared controller instance handles a particular request type - controllers, interceptors run in the IoC container - allows multiple DispatcherServlets that can share an “application context” - Interface based not class-based
  34. Spring MVC – a single shared controller instance handles a particular request type - controllers, interceptors run in the IoC container - allows multiple DispatcherServlets that can share an “application context” - Interface based not class-based
  35. Spring MVC – a single shared controller instance handles a particular request type - controllers, interceptors run in the IoC container - allows multiple DispatcherServlets that can share an “application context” - Interface based not class-based
  36. Spring MVC – a single shared controller instance handles a particular request type - controllers, interceptors run in the IoC container - allows multiple DispatcherServlets that can share an “application context” - Interface based not class-based
  37. Spring MVC – a single shared controller instance handles a particular request type - controllers, interceptors run in the IoC container - allows multiple DispatcherServlets that can share an “application context” - Interface based not class-based
  38. Spring MVC – a single shared controller instance handles a particular request type - controllers, interceptors run in the IoC container - allows multiple DispatcherServlets that can share an “application context” - Interface based not class-based
  39. Spring MVC – a single shared controller instance handles a particular request type - controllers, interceptors run in the IoC container - allows multiple DispatcherServlets that can share an “application context” - Interface based not class-based
  40. Spring MVC – a single shared controller instance handles a particular request type - controllers, interceptors run in the IoC container - allows multiple DispatcherServlets that can share an “application context” - Interface based not class-based
  41. Spring MVC – a single shared controller instance handles a particular request type - controllers, interceptors run in the IoC container - allows multiple DispatcherServlets that can share an “application context” - Interface based not class-based
  42. Spring MVC – a single shared controller instance handles a particular request type - controllers, interceptors run in the IoC container - allows multiple DispatcherServlets that can share an “application context” - Interface based not class-based
  43. Spring MVC – a single shared controller instance handles a particular request type - controllers, interceptors run in the IoC container - allows multiple DispatcherServlets that can share an “application context” - Interface based not class-based
  44. Spring MVC – a single shared controller instance handles a particular request type - controllers, interceptors run in the IoC container - allows multiple DispatcherServlets that can share an “application context” - Interface based not class-based
  45. Spring MVC – a single shared controller instance handles a particular request type - controllers, interceptors run in the IoC container - allows multiple DispatcherServlets that can share an “application context” - Interface based not class-based
  46. Spring MVC – a single shared controller instance handles a particular request type - controllers, interceptors run in the IoC container - allows multiple DispatcherServlets that can share an “application context” - Interface based not class-based
  47. Spring MVC – a single shared controller instance handles a particular request type - controllers, interceptors run in the IoC container - allows multiple DispatcherServlets that can share an “application context” - Interface based not class-based
  48. Spring MVC – a single shared controller instance handles a particular request type - controllers, interceptors run in the IoC container - allows multiple DispatcherServlets that can share an “application context” - Interface based not class-based
  49. Spring MVC – a single shared controller instance handles a particular request type - controllers, interceptors run in the IoC container - allows multiple DispatcherServlets that can share an “application context” - Interface based not class-based
  50. Spring MVC – a single shared controller instance handles a particular request type - controllers, interceptors run in the IoC container - allows multiple DispatcherServlets that can share an “application context” - Interface based not class-based
  51. Spring MVC – a single shared controller instance handles a particular request type - controllers, interceptors run in the IoC container - allows multiple DispatcherServlets that can share an “application context” - Interface based not class-based
  52. Spring MVC – a single shared controller instance handles a particular request type - controllers, interceptors run in the IoC container - allows multiple DispatcherServlets that can share an “application context” - Interface based not class-based
  53. Spring MVC – a single shared controller instance handles a particular request type - controllers, interceptors run in the IoC container - allows multiple DispatcherServlets that can share an “application context” - Interface based not class-based