SlideShare ist ein Scribd-Unternehmen logo
1 von 80
Spring By Example
     Oleksiy Rezchykov
      Eugene Scripnik
About us
 Software Engineers

 Working with Spring since 2006

 Pragmatic programmers

 SpringByExample.com.ua
   founders




                  SpringByExample.com.ua
                                           2
                        @ua_spring
Contents
 Intro

 IoC using Spring

 Persistence with Spring

 Web applications with Spring MVC




                     SpringByExample.com.ua
                                              3
                           @ua_spring
Intro
 What we will do today?

 Meet some new faces

 Learn some new stuff

 Code some new stuff




                  SpringByExample.com.ua
                                           4
                        @ua_spring
SpringFramework
            history
 In October 2002 Rod Johnson
   wrote his famous book

 The first milestone release 1.0 -
   June 2004

 Company renamed from
   Interface21 to SpringSource in
   2007

 SpringSource acquired by
   VMWare in 2009

                    SpringByExample.com.ua
                                             5
                          @ua_spring
Spring in 2012




   SpringByExample.com.ua
                            6
         @ua_spring
IoC using Spring
   Buiding xml contexts

   Bean scopes & lifecycles

   Constructor vs Setter injection

   Property placeholders

   p & c and util name spaces

   Annotation context

   Using component scan

   AOP usage

   Spring AOP vs AspectJ

                            SpringByExample.com.ua
                                                     7
                                  @ua_spring
Inversion of Control
 Inversion of regular approach where object was
   responsible for satisfying it’s own dependencies

 Implementation of Dependency Injection

 Container instantiates and wires dependencies




                   SpringByExample.com.ua
                                                      8
                         @ua_spring
IoC
 Pros vs Cons (to discuss)




                  SpringByExample.com.ua
                                           9
                        @ua_spring
Injection types
 Setter injection– when you are using setter to fulfill
   bean dependency

 Constructor injection – when constructor is called to
   set-up a bean with dependencies




                     SpringByExample.com.ua
                                                           10
                           @ua_spring
CI vs SI
 Pro vs Cons (to discuss)




                  SpringByExample.com.ua
                                           11
                        @ua_spring
Context
 An object which contains beans declarations with
   their dependencies

 BeanFactory interface implementation




                   SpringByExample.com.ua
                                                     12
                         @ua_spring
XML namespaces




    SpringByExample.com.ua
                             13
          @ua_spring
Context




SpringByExample.com.ua
                         14
      @ua_spring
Context usage




   SpringByExample.com.ua
                            15
         @ua_spring
Bean lifecycle
 Depends on scope and lazy initialization

 Main bean scopes:

 Singleton and Prototype

(Also there are multiple web scopes)




                   SpringByExample.com.ua
                                             16
                         @ua_spring
Bean instantiation order




        SpringByExample.com.ua
                                 17
              @ua_spring
Bean Post-processing
                • Bean instantiated for singletons with
    Bean
instantiation
                  eager initialization


Dependency
                • Dependencies are injected into beans
 injection



                • Bean post-processing actions
Bean post-
processing
                • You can put your custom logic in here


                         SpringByExample.com.ua
                                                          18
                               @ua_spring
Property Editors




    SpringByExample.com.ua
                             19
          @ua_spring
Multiple config files




      SpringByExample.com.ua
                               20
            @ua_spring
Bean definition
 inheritance




    SpringByExample.com.ua
                             21
          @ua_spring
Inner Beans




  SpringByExample.com.ua
                           22
        @ua_spring
Factory Method




   SpringByExample.com.ua
                            23
         @ua_spring
Map, List, Set, Prop,
        Null




       SpringByExample.com.ua
                                24
             @ua_spring
Map, List, Set, Prop, Nul
            l




         SpringByExample.com.ua
                                  25
               @ua_spring
Util namespace




   SpringByExample.com.ua
                            26
         @ua_spring
Component model




    SpringByExample.com.ua
                             27
          @ua_spring
@Autowired
 Spring proprietary annotation for property injection

 Supports @Qualifier to select implementation by
   name if more than one exists in context

 Has required parameter to enforce dependency
   loading




                    SpringByExample.com.ua
                                                         28
                          @ua_spring
@Autowired




  SpringByExample.com.ua
                           29
        @ua_spring
@Inject
 Context and Dependency Injection (CDI) standard
   JSR-299




                  SpringByExample.com.ua
                                                    30
                        @ua_spring
@Resource
 JSR 250 (Common annotations)

 Supports @PostConstruct and @PreDestroy as
  well




                 SpringByExample.com.ua
                                               31
                       @ua_spring
Autowiring
An appropriate bean for dependency is found through:

 Type

 Name

 Type and Name combination




                   SpringByExample.com.ua
                                                       32
                         @ua_spring
Resource loading and
       i18n




      SpringByExample.com.ua
                               33
            @ua_spring
Resource loading and
       i18n




      SpringByExample.com.ua
                               34
            @ua_spring
SpEl
 Stands for Spring Expression Language

 Can be used in the xml context

 Can be used in bean classes




                  SpringByExample.com.ua
                                           35
                        @ua_spring
SpEl




SpringByExample.com.ua
                         36
      @ua_spring
Java Spring Config
 @Configuration

 @Bean

 Support for Environment and Profiles




                   SpringByExample.com.ua
                                            37
                         @ua_spring
Java Spring Config




     SpringByExample.com.ua
                              38
           @ua_spring
Environment abstraction
   & context profiles
 Environment abstraction introduced in Spring 3.1

 Can be declaratively and programmatically
   configured

 Affects property resolution

 Affects bean profiles




                   SpringByExample.com.ua
                                                     39
                         @ua_spring
Environment abstraction
   & context profiles




        SpringByExample.com.ua
                                 40
              @ua_spring
Environment abstraction
   & context profiles




        SpringByExample.com.ua
                                 41
              @ua_spring
AOP
A programming paradigm which allows to separate
cross-cutting concerns

Cross-cutting logic:

 Logging

 Tracing

 Security




                       SpringByExample.com.ua
                                                  42
                             @ua_spring
AOP
 Aspect

 Advice

 Join point

 Pointcut




               SpringByExample.com.ua
                                        43
                     @ua_spring
AOP




SpringByExample.com.ua
                         44
      @ua_spring
Spring AOP
 Spring AOP defaults to using standard J2SE
   dynamic proxies for AOP proxies. This enables any
   interface (or set of interfaces) to be proxied.

 Spring AOP can also use CGLIB proxies. This is
   necessary to proxy classes, rather than interfaces

 It is good practice to program to interfaces rather
   than classes, business classes normally will
   implement one or more business interfaces.



                    SpringByExample.com.ua
                                                        45
                          @ua_spring
AspectJ
 Spring AOP is often uses the AspectJ declaration
   style
 AspectJ itself uses Load Time Weaving (LTW) to
   modify the bean code according to Aspect logic
 LTW could do much more than dynamic proxies but it
   is more time-consuming operation. This means that
   LTW has a performance drawback.




                 SpringByExample.com.ua
                                                       46
                       @ua_spring
Persistence with Spring
 Building DAO

 Embedded Datasources

 JDBC vs ORM DAO’s

 Integration testing with Spring

 @Transactional & transactions with Spring




                    SpringByExample.com.ua
                                              47
                          @ua_spring
Spring supports
 JDBC

 JPA

 JDO

 Concrete ORM

 NoSQL templates (Mongo/Redis)

 Graph DB abstractions - Spring Data Graph project



                  SpringByExample.com.ua
                                                      48
                        @ua_spring
Persistence layer
           • Persistence service which has domain specific logic
 Service



           • Spring JDBCTemplate
           • SessionFactory, EntityManagerFactory
Repository
 (DAO)     • Redis/Mongo template



           • RDBMS (or NoSQL)
   DB




                         SpringByExample.com.ua
                                                                   49
                               @ua_spring
JDBCTemplate
 Useful interface

 No boilerplate code

 Exception handling




                     SpringByExample.com.ua
                                              50
                           @ua_spring
JDBCTemplate




   SpringByExample.com.ua
                            51
         @ua_spring
JDBC namespace




    SpringByExample.com.ua
                             52
          @ua_spring
Intro to Hibernate
Object Relational Mapping - is a programming
technique for converting data between incompatible
type systems in object-oriented programming
languages. This creates, in effect, a "virtual object
database" that can be used from within the
programming language.




                    SpringByExample.com.ua
                                                        53
                          @ua_spring
ORM main challenges
 Object inheritance

 Object relations




                     SpringByExample.com.ua
                                              54
                           @ua_spring
Hibernate main parts
 SessionFactory

 Session

 Entity




                   SpringByExample.com.ua
                                            55
                         @ua_spring
Transactions in Spring
 Support for ACID transactions

 Declarative and programmatic




                  SpringByExample.com.ua
                                           56
                        @ua_spring
Transaction managers
 Spring support both container managed and
   framework managed transactions

Managers:

 DataSourceTransactionManager

 HibernateTransactionManager

 JPATransactionManager

 JTATransactionManager


                  SpringByExample.com.ua
                                              57
                        @ua_spring
@Transactional
 Isolation levels

 Transaction propagation

 Read-only transactions




                     SpringByExample.com.ua
                                              58
                           @ua_spring
Read-only transactions
    A read-only transaction can be used when your
    code reads but does not modify data. Read-only
    transactions can be a useful optimization in some
    cases, such as when you are using Hibernate.




                    SpringByExample.com.ua
                                                        59
                          @ua_spring
Isolation levels
 DEFAULT - The default isolation level for the
   underlying resource (usually this is the
   READ_COMMITTED isolation level)




                    SpringByExample.com.ua
                                                  60
                          @ua_spring
Isolation levels
 READ_UNCOMMITTED - Least restrictive isolation
  level. A transaction can read data updates even if
  they haven't yet been committed. (The updates
  might subsequently be rolled-back).




                   SpringByExample.com.ua
                                                       61
                         @ua_spring
Isolation levels
 READ_COMMITTED - A transaction can only read
  data that has already been committed. The
  transaction doesn't see uncommitted updates.




                  SpringByExample.com.ua
                                                 62
                        @ua_spring
Isolation levels
 REPEATABLE_READ - A transaction always reads
  the same value after it has read some data. Other
  transactions can update the data in parallel with the
  original transaction.




                   SpringByExample.com.ua
                                                          63
                         @ua_spring
Isolation levels
 SERIALIZABLE - This is the most restrictive
   isolation level. Transactions are completely isolated
   from each other. Resource managers frequently
   implement this isolation level by locking large
   amounts of data




                    SpringByExample.com.ua
                                                           64
                          @ua_spring
Propagation
 NOT_SUPPORTED

Suspends client's transaction until bean method is complete




                     SpringByExample.com.ua
                                                              65
                           @ua_spring
Propagation
 SUPPORTS

If client has transaction, bean method is included in it

If client doesn't have transaction, bean method doesn't
create one




                       SpringByExample.com.ua
                                                           66
                             @ua_spring
Propagation
 REQUIRED

If client has a transaction, bean method is included in it

If client doesn't have a transaction, bean method creates
one




                       SpringByExample.com.ua
                                                             67
                             @ua_spring
Propagation
 REQUIRES_NEW

If client has a transaction, bean method creates new one
anyway

If client doesn't have a transaction, bean method creates
one




                      SpringByExample.com.ua
                                                            68
                            @ua_spring
Propagation
 MANDATORY

If client has a transaction, bean method uses it

If client doesn't have a transaction, exception!




                       SpringByExample.com.ua
                                                   69
                             @ua_spring
Propagation
 NEVER

If client has a transaction, exception!

If client doesn't have transaction, bean method doesn't
create one




                       SpringByExample.com.ua
                                                          70
                             @ua_spring
Persistence layer testing
 Context loading in test

 Environment abstraction and profiles usage

 Transactional methods

 Embedded data source could be used




                   SpringByExample.com.ua
                                               71
                         @ua_spring
Persistence layer testing




         SpringByExample.com.ua
                                  72
               @ua_spring
Spring MVC
 Application context

 Dispatcher Servlet and it’s context

 Controllers and mappings

 Implementing CRUD logic

 Using Spring for UI tests




                   SpringByExample.com.ua
                                            73
                         @ua_spring
Application & Dispatcher
     servlet context




        SpringByExample.com.ua
                                 74
              @ua_spring
Front controller and
       MVC




      SpringByExample.com.ua
                               75
            @ua_spring
URL mappings
 @RequestMapping




               SpringByExample.com.ua
                                        76
                     @ua_spring
View resolvers
 AbstractCachingViewResolver

 XmlViewResolver

 ResourceBundleViewResolver

 UrlBasedViewResolver

 InternalResourceViewResolver

 VelocityViewResolver / FreeMarkerViewResolver

 ContentNegotiatingViewResolver
                  SpringByExample.com.ua
                                                  77
                        @ua_spring
View resolvers




   SpringByExample.com.ua
                            78
         @ua_spring
CRUD in one place




     SpringByExample.com.ua
                              79
           @ua_spring
Using Spring for UI tests
 Integration testing of Controllers

 Spring as a framework for Selenium UI tests




                    SpringByExample.com.ua
                                                80
                          @ua_spring

Weitere ähnliche Inhalte

Andere mochten auch

Struts & spring framework issues
Struts & spring framework issuesStruts & spring framework issues
Struts & spring framework issuesPrashant Seth
 
A PRESENTATION ON STRUTS & HIBERNATE
A PRESENTATION ON STRUTS & HIBERNATEA PRESENTATION ON STRUTS & HIBERNATE
A PRESENTATION ON STRUTS & HIBERNATETushar Choudhary
 
Hibernate architecture
Hibernate architectureHibernate architecture
Hibernate architectureAnurag
 
Introduction to j2 ee frameworks
Introduction to j2 ee frameworksIntroduction to j2 ee frameworks
Introduction to j2 ee frameworksMukesh Kumar
 
Introduction to Java Enterprise Edition
Introduction to Java Enterprise EditionIntroduction to Java Enterprise Edition
Introduction to Java Enterprise EditionAbdalla Mahmoud
 
Java & J2EE Struts with Hibernate Framework
Java & J2EE Struts with Hibernate FrameworkJava & J2EE Struts with Hibernate Framework
Java & J2EE Struts with Hibernate FrameworkMohit Belwal
 
ORM, JPA, & Hibernate Overview
ORM, JPA, & Hibernate OverviewORM, JPA, & Hibernate Overview
ORM, JPA, & Hibernate OverviewBrett Meyer
 
Creating modern java web applications based on struts2 and angularjs
Creating modern java web applications based on struts2 and angularjsCreating modern java web applications based on struts2 and angularjs
Creating modern java web applications based on struts2 and angularjsJohannes Geppert
 
Hibernate Presentation
Hibernate  PresentationHibernate  Presentation
Hibernate Presentationguest11106b
 
Lecture 8 Enterprise Java Beans (EJB)
Lecture 8  Enterprise Java Beans (EJB)Lecture 8  Enterprise Java Beans (EJB)
Lecture 8 Enterprise Java Beans (EJB)Fahad Golra
 
Spring Framework - Core
Spring Framework - CoreSpring Framework - Core
Spring Framework - CoreDzmitry Naskou
 

Andere mochten auch (20)

Struts & spring framework issues
Struts & spring framework issuesStruts & spring framework issues
Struts & spring framework issues
 
Struts2
Struts2Struts2
Struts2
 
Struts2
Struts2Struts2
Struts2
 
Struts
StrutsStruts
Struts
 
Struts2
Struts2Struts2
Struts2
 
A PRESENTATION ON STRUTS & HIBERNATE
A PRESENTATION ON STRUTS & HIBERNATEA PRESENTATION ON STRUTS & HIBERNATE
A PRESENTATION ON STRUTS & HIBERNATE
 
Hibernate 3
Hibernate 3Hibernate 3
Hibernate 3
 
Hibernate architecture
Hibernate architectureHibernate architecture
Hibernate architecture
 
Introduction to j2 ee frameworks
Introduction to j2 ee frameworksIntroduction to j2 ee frameworks
Introduction to j2 ee frameworks
 
Introduction to Java Enterprise Edition
Introduction to Java Enterprise EditionIntroduction to Java Enterprise Edition
Introduction to Java Enterprise Edition
 
Java Enterprise Edition
Java Enterprise EditionJava Enterprise Edition
Java Enterprise Edition
 
Struts framework
Struts frameworkStruts framework
Struts framework
 
Why do I hate Hibernate?
Why do I hate Hibernate?Why do I hate Hibernate?
Why do I hate Hibernate?
 
Java & J2EE Struts with Hibernate Framework
Java & J2EE Struts with Hibernate FrameworkJava & J2EE Struts with Hibernate Framework
Java & J2EE Struts with Hibernate Framework
 
ORM, JPA, & Hibernate Overview
ORM, JPA, & Hibernate OverviewORM, JPA, & Hibernate Overview
ORM, JPA, & Hibernate Overview
 
Creating modern java web applications based on struts2 and angularjs
Creating modern java web applications based on struts2 and angularjsCreating modern java web applications based on struts2 and angularjs
Creating modern java web applications based on struts2 and angularjs
 
Hibernate Presentation
Hibernate  PresentationHibernate  Presentation
Hibernate Presentation
 
Lecture 8 Enterprise Java Beans (EJB)
Lecture 8  Enterprise Java Beans (EJB)Lecture 8  Enterprise Java Beans (EJB)
Lecture 8 Enterprise Java Beans (EJB)
 
Spring ppt
Spring pptSpring ppt
Spring ppt
 
Spring Framework - Core
Spring Framework - CoreSpring Framework - Core
Spring Framework - Core
 

Ähnlich wie Spring By Example One Day Workshop

Spring training
Spring trainingSpring training
Spring trainingshah_d_p
 
Decoupling shared code with state that needs to cleared in between uses
Decoupling shared code with state that needs to cleared in between usesDecoupling shared code with state that needs to cleared in between uses
Decoupling shared code with state that needs to cleared in between usesMichael Fons
 
Spring framework
Spring frameworkSpring framework
Spring frameworkvietduc17
 
Spring Interview Questions and Answers | Spring Tutorial | Spring Framework T...
Spring Interview Questions and Answers | Spring Tutorial | Spring Framework T...Spring Interview Questions and Answers | Spring Tutorial | Spring Framework T...
Spring Interview Questions and Answers | Spring Tutorial | Spring Framework T...Edureka!
 
Spring - CDI Interop
Spring - CDI InteropSpring - CDI Interop
Spring - CDI InteropRay Ploski
 
Java spring framework
Java spring frameworkJava spring framework
Java spring frameworkRajiv Gupta
 
[QaOps] Continuouss Integration | Pipeline strategy
[QaOps] Continuouss Integration | Pipeline strategy[QaOps] Continuouss Integration | Pipeline strategy
[QaOps] Continuouss Integration | Pipeline strategyRafael Lima
 
Spring framework
Spring frameworkSpring framework
Spring frameworkAjit Koti
 
Introduction to Spring Framework
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring FrameworkDineesha Suraweera
 
Spring framework Introduction
Spring framework IntroductionSpring framework Introduction
Spring framework IntroductionAnuj Singh Rajput
 
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
 
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
 

Ähnlich wie Spring By Example One Day Workshop (20)

Spring Basics
Spring BasicsSpring Basics
Spring Basics
 
Spring training
Spring trainingSpring training
Spring training
 
Lo nuevo en Spring 3.0
Lo nuevo  en Spring 3.0Lo nuevo  en Spring 3.0
Lo nuevo en Spring 3.0
 
Decoupling shared code with state that needs to cleared in between uses
Decoupling shared code with state that needs to cleared in between usesDecoupling shared code with state that needs to cleared in between uses
Decoupling shared code with state that needs to cleared in between uses
 
Spring core
Spring coreSpring core
Spring core
 
Spring framework
Spring frameworkSpring framework
Spring framework
 
Spring framework
Spring frameworkSpring framework
Spring framework
 
Spring Interview Questions and Answers | Spring Tutorial | Spring Framework T...
Spring Interview Questions and Answers | Spring Tutorial | Spring Framework T...Spring Interview Questions and Answers | Spring Tutorial | Spring Framework T...
Spring Interview Questions and Answers | Spring Tutorial | Spring Framework T...
 
Spring - CDI Interop
Spring - CDI InteropSpring - CDI Interop
Spring - CDI Interop
 
Spring framework
Spring frameworkSpring framework
Spring framework
 
Spring Framework -I
Spring Framework -ISpring Framework -I
Spring Framework -I
 
Java spring framework
Java spring frameworkJava spring framework
Java spring framework
 
[QaOps] Continuouss Integration | Pipeline strategy
[QaOps] Continuouss Integration | Pipeline strategy[QaOps] Continuouss Integration | Pipeline strategy
[QaOps] Continuouss Integration | Pipeline strategy
 
Java Spring Framework
Java Spring FrameworkJava Spring Framework
Java Spring Framework
 
Spring framework
Spring frameworkSpring framework
Spring framework
 
Spring Framework
Spring FrameworkSpring Framework
Spring Framework
 
Introduction to Spring Framework
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring Framework
 
Spring framework Introduction
Spring framework IntroductionSpring framework Introduction
Spring framework Introduction
 
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
 
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
 

Kürzlich hochgeladen

08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 

Kürzlich hochgeladen (20)

08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 

Spring By Example One Day Workshop

  • 1. Spring By Example Oleksiy Rezchykov Eugene Scripnik
  • 2. About us  Software Engineers  Working with Spring since 2006  Pragmatic programmers  SpringByExample.com.ua founders SpringByExample.com.ua 2 @ua_spring
  • 3. Contents  Intro  IoC using Spring  Persistence with Spring  Web applications with Spring MVC SpringByExample.com.ua 3 @ua_spring
  • 4. Intro  What we will do today?  Meet some new faces  Learn some new stuff  Code some new stuff SpringByExample.com.ua 4 @ua_spring
  • 5. SpringFramework history  In October 2002 Rod Johnson wrote his famous book  The first milestone release 1.0 - June 2004  Company renamed from Interface21 to SpringSource in 2007  SpringSource acquired by VMWare in 2009 SpringByExample.com.ua 5 @ua_spring
  • 6. Spring in 2012 SpringByExample.com.ua 6 @ua_spring
  • 7. IoC using Spring  Buiding xml contexts  Bean scopes & lifecycles  Constructor vs Setter injection  Property placeholders  p & c and util name spaces  Annotation context  Using component scan  AOP usage  Spring AOP vs AspectJ SpringByExample.com.ua 7 @ua_spring
  • 8. Inversion of Control  Inversion of regular approach where object was responsible for satisfying it’s own dependencies  Implementation of Dependency Injection  Container instantiates and wires dependencies SpringByExample.com.ua 8 @ua_spring
  • 9. IoC  Pros vs Cons (to discuss) SpringByExample.com.ua 9 @ua_spring
  • 10. Injection types  Setter injection– when you are using setter to fulfill bean dependency  Constructor injection – when constructor is called to set-up a bean with dependencies SpringByExample.com.ua 10 @ua_spring
  • 11. CI vs SI  Pro vs Cons (to discuss) SpringByExample.com.ua 11 @ua_spring
  • 12. Context  An object which contains beans declarations with their dependencies  BeanFactory interface implementation SpringByExample.com.ua 12 @ua_spring
  • 13. XML namespaces SpringByExample.com.ua 13 @ua_spring
  • 15. Context usage SpringByExample.com.ua 15 @ua_spring
  • 16. Bean lifecycle  Depends on scope and lazy initialization  Main bean scopes: Singleton and Prototype (Also there are multiple web scopes) SpringByExample.com.ua 16 @ua_spring
  • 17. Bean instantiation order SpringByExample.com.ua 17 @ua_spring
  • 18. Bean Post-processing • Bean instantiated for singletons with Bean instantiation eager initialization Dependency • Dependencies are injected into beans injection • Bean post-processing actions Bean post- processing • You can put your custom logic in here SpringByExample.com.ua 18 @ua_spring
  • 19. Property Editors SpringByExample.com.ua 19 @ua_spring
  • 20. Multiple config files SpringByExample.com.ua 20 @ua_spring
  • 21. Bean definition inheritance SpringByExample.com.ua 21 @ua_spring
  • 22. Inner Beans SpringByExample.com.ua 22 @ua_spring
  • 23. Factory Method SpringByExample.com.ua 23 @ua_spring
  • 24. Map, List, Set, Prop, Null SpringByExample.com.ua 24 @ua_spring
  • 25. Map, List, Set, Prop, Nul l SpringByExample.com.ua 25 @ua_spring
  • 26. Util namespace SpringByExample.com.ua 26 @ua_spring
  • 27. Component model SpringByExample.com.ua 27 @ua_spring
  • 28. @Autowired  Spring proprietary annotation for property injection  Supports @Qualifier to select implementation by name if more than one exists in context  Has required parameter to enforce dependency loading SpringByExample.com.ua 28 @ua_spring
  • 30. @Inject  Context and Dependency Injection (CDI) standard JSR-299 SpringByExample.com.ua 30 @ua_spring
  • 31. @Resource  JSR 250 (Common annotations)  Supports @PostConstruct and @PreDestroy as well SpringByExample.com.ua 31 @ua_spring
  • 32. Autowiring An appropriate bean for dependency is found through:  Type  Name  Type and Name combination SpringByExample.com.ua 32 @ua_spring
  • 33. Resource loading and i18n SpringByExample.com.ua 33 @ua_spring
  • 34. Resource loading and i18n SpringByExample.com.ua 34 @ua_spring
  • 35. SpEl  Stands for Spring Expression Language  Can be used in the xml context  Can be used in bean classes SpringByExample.com.ua 35 @ua_spring
  • 37. Java Spring Config  @Configuration  @Bean  Support for Environment and Profiles SpringByExample.com.ua 37 @ua_spring
  • 38. Java Spring Config SpringByExample.com.ua 38 @ua_spring
  • 39. Environment abstraction & context profiles  Environment abstraction introduced in Spring 3.1  Can be declaratively and programmatically configured  Affects property resolution  Affects bean profiles SpringByExample.com.ua 39 @ua_spring
  • 40. Environment abstraction & context profiles SpringByExample.com.ua 40 @ua_spring
  • 41. Environment abstraction & context profiles SpringByExample.com.ua 41 @ua_spring
  • 42. AOP A programming paradigm which allows to separate cross-cutting concerns Cross-cutting logic:  Logging  Tracing  Security SpringByExample.com.ua 42 @ua_spring
  • 43. AOP  Aspect  Advice  Join point  Pointcut SpringByExample.com.ua 43 @ua_spring
  • 44. AOP SpringByExample.com.ua 44 @ua_spring
  • 45. Spring AOP  Spring AOP defaults to using standard J2SE dynamic proxies for AOP proxies. This enables any interface (or set of interfaces) to be proxied.  Spring AOP can also use CGLIB proxies. This is necessary to proxy classes, rather than interfaces  It is good practice to program to interfaces rather than classes, business classes normally will implement one or more business interfaces. SpringByExample.com.ua 45 @ua_spring
  • 46. AspectJ  Spring AOP is often uses the AspectJ declaration style  AspectJ itself uses Load Time Weaving (LTW) to modify the bean code according to Aspect logic  LTW could do much more than dynamic proxies but it is more time-consuming operation. This means that LTW has a performance drawback. SpringByExample.com.ua 46 @ua_spring
  • 47. Persistence with Spring  Building DAO  Embedded Datasources  JDBC vs ORM DAO’s  Integration testing with Spring  @Transactional & transactions with Spring SpringByExample.com.ua 47 @ua_spring
  • 48. Spring supports  JDBC  JPA  JDO  Concrete ORM  NoSQL templates (Mongo/Redis)  Graph DB abstractions - Spring Data Graph project SpringByExample.com.ua 48 @ua_spring
  • 49. Persistence layer • Persistence service which has domain specific logic Service • Spring JDBCTemplate • SessionFactory, EntityManagerFactory Repository (DAO) • Redis/Mongo template • RDBMS (or NoSQL) DB SpringByExample.com.ua 49 @ua_spring
  • 50. JDBCTemplate  Useful interface  No boilerplate code  Exception handling SpringByExample.com.ua 50 @ua_spring
  • 51. JDBCTemplate SpringByExample.com.ua 51 @ua_spring
  • 52. JDBC namespace SpringByExample.com.ua 52 @ua_spring
  • 53. Intro to Hibernate Object Relational Mapping - is a programming technique for converting data between incompatible type systems in object-oriented programming languages. This creates, in effect, a "virtual object database" that can be used from within the programming language. SpringByExample.com.ua 53 @ua_spring
  • 54. ORM main challenges  Object inheritance  Object relations SpringByExample.com.ua 54 @ua_spring
  • 55. Hibernate main parts  SessionFactory  Session  Entity SpringByExample.com.ua 55 @ua_spring
  • 56. Transactions in Spring  Support for ACID transactions  Declarative and programmatic SpringByExample.com.ua 56 @ua_spring
  • 57. Transaction managers  Spring support both container managed and framework managed transactions Managers:  DataSourceTransactionManager  HibernateTransactionManager  JPATransactionManager  JTATransactionManager SpringByExample.com.ua 57 @ua_spring
  • 58. @Transactional  Isolation levels  Transaction propagation  Read-only transactions SpringByExample.com.ua 58 @ua_spring
  • 59. Read-only transactions  A read-only transaction can be used when your code reads but does not modify data. Read-only transactions can be a useful optimization in some cases, such as when you are using Hibernate. SpringByExample.com.ua 59 @ua_spring
  • 60. Isolation levels  DEFAULT - The default isolation level for the underlying resource (usually this is the READ_COMMITTED isolation level) SpringByExample.com.ua 60 @ua_spring
  • 61. Isolation levels  READ_UNCOMMITTED - Least restrictive isolation level. A transaction can read data updates even if they haven't yet been committed. (The updates might subsequently be rolled-back). SpringByExample.com.ua 61 @ua_spring
  • 62. Isolation levels  READ_COMMITTED - A transaction can only read data that has already been committed. The transaction doesn't see uncommitted updates. SpringByExample.com.ua 62 @ua_spring
  • 63. Isolation levels  REPEATABLE_READ - A transaction always reads the same value after it has read some data. Other transactions can update the data in parallel with the original transaction. SpringByExample.com.ua 63 @ua_spring
  • 64. Isolation levels  SERIALIZABLE - This is the most restrictive isolation level. Transactions are completely isolated from each other. Resource managers frequently implement this isolation level by locking large amounts of data SpringByExample.com.ua 64 @ua_spring
  • 65. Propagation  NOT_SUPPORTED Suspends client's transaction until bean method is complete SpringByExample.com.ua 65 @ua_spring
  • 66. Propagation  SUPPORTS If client has transaction, bean method is included in it If client doesn't have transaction, bean method doesn't create one SpringByExample.com.ua 66 @ua_spring
  • 67. Propagation  REQUIRED If client has a transaction, bean method is included in it If client doesn't have a transaction, bean method creates one SpringByExample.com.ua 67 @ua_spring
  • 68. Propagation  REQUIRES_NEW If client has a transaction, bean method creates new one anyway If client doesn't have a transaction, bean method creates one SpringByExample.com.ua 68 @ua_spring
  • 69. Propagation  MANDATORY If client has a transaction, bean method uses it If client doesn't have a transaction, exception! SpringByExample.com.ua 69 @ua_spring
  • 70. Propagation  NEVER If client has a transaction, exception! If client doesn't have transaction, bean method doesn't create one SpringByExample.com.ua 70 @ua_spring
  • 71. Persistence layer testing  Context loading in test  Environment abstraction and profiles usage  Transactional methods  Embedded data source could be used SpringByExample.com.ua 71 @ua_spring
  • 72. Persistence layer testing SpringByExample.com.ua 72 @ua_spring
  • 73. Spring MVC  Application context  Dispatcher Servlet and it’s context  Controllers and mappings  Implementing CRUD logic  Using Spring for UI tests SpringByExample.com.ua 73 @ua_spring
  • 74. Application & Dispatcher servlet context SpringByExample.com.ua 74 @ua_spring
  • 75. Front controller and MVC SpringByExample.com.ua 75 @ua_spring
  • 76. URL mappings  @RequestMapping SpringByExample.com.ua 76 @ua_spring
  • 77. View resolvers  AbstractCachingViewResolver  XmlViewResolver  ResourceBundleViewResolver  UrlBasedViewResolver  InternalResourceViewResolver  VelocityViewResolver / FreeMarkerViewResolver  ContentNegotiatingViewResolver SpringByExample.com.ua 77 @ua_spring
  • 78. View resolvers SpringByExample.com.ua 78 @ua_spring
  • 79. CRUD in one place SpringByExample.com.ua 79 @ua_spring
  • 80. Using Spring for UI tests  Integration testing of Controllers  Spring as a framework for Selenium UI tests SpringByExample.com.ua 80 @ua_spring

Hinweis der Redaktion

  1. Когда первый раз задаете вопрос – представьтесь и расскажите про свой опыт.Скайп чат.
  2. Bean tag attrubutes: id vs namep& c context
  3. Bean tag attrubutes: id vs namep& c context Constur-argClasspath*:, file:,url:
  4. Java code example of context usageBean overriding (id)
  5. toString()
  6. Number, Boolean, Date, Property, Locale, Pattern
  7. Locale resolver
  8. Locale resolver
  9. Polyglot persistence
  10. Some words about JDBC
  11. Some words about JDBC