SlideShare a Scribd company logo
Spring Training TechFerry Infotech Pvt. Ltd. (http://www.techferry.com/)
Conversations Introduction to Spring  Concepts: Annotations, MVC, IOC/DI, Auto wiring Spring Bean/Resource Management Spring MVC, Form Validations. Unit Testing  Spring Security – Users, Roles, Permissions.  Code Demo  CRUD using Spring, Hibernate, MySQL. Spring security example. REST/jQuery/Ajax example
Spring - Introduction Exercise: What do we need in an enterprise application?   Database Access, Connection Pools?  Transactions?  Security, Authentication, Authorization? Business Logic Objects? Workflow/Screen Flow? Messaging/emails? Service Bus? Concurrency/Scalability?  Can somebody wire all the needed components? Do we have to learn everything before we can start?
Hello Spring Spring is potentially a one-stop shop, addressing most infrastructure concerns of typical web applications so you focus only on your business logic. Spring is both comprehensive and modular use just about any part of it in isolation, yet its architecture is internally consistent. maximum value from your learning curve.
What is Spring? Open source and lightweight web-application framework  Framework for wiring the entire application  Collection of many different components  Reduces code and speeds up development    Spring is essentially a technology dedicated to enabling you to build applications using POJOs.
Why Spring? Spring Enables POJO Programming  Application code does not depend on spring API’s  Dependency Injection and Inversion of Control simplifies coding Promotes decoupling and re-usability    Features: Lightweight  Inversion of Control (IoC)  Aspect oriented (AOP)  MVC Framework  Transaction Management  JDBC  Ibatis / Hibernate
Spring Modules
What else Spring do? Spring Web Flow Spring Integration Spring Web-Services  Spring MVC Spring Security Spring Batch  Spring Social Spring Mobile        ... and let it ever expand ...
Inversion of Control/Dependency Injection "Don't call me, I'll call you."    IoC moves the responsibility for making things happen into the framework Eliminates lookup code from within the application  Loose coupling, minimum effort and least intrusive mechanism 
IOC/DI  
IOC/DI Non IOC Example: class MovieLister...     private MovieFinder finder;     public MovieLister() {       finder = new MovieFinderImpl();     }  public interface MovieFinder {     List findAll();  }  class MovieFinderImpl ... {    public List findAll() {      ...    } }
IOC/DI IoC Example: DI exists in major two variants: Setter Injection              public class MovieLister {                 private MovieFinder movieFinder;                  public void setMovieFinder(MovieFinder movieFinder) {                     this.movieFinder = movieFinder;                 }         } Constructor Injection       public class MovieLister{ private MovieFinder movieFinder; public MovieLister(MovieFinder movieFinder) {     this.movieFinder = movieFinder; }       }
Code Demo ....  Annotations: @Component, @Service,  @Repository  Annotation:  @Autowire web.xml - Context loader listener to scan components     <context:annotation-config />     <context:component-scan base-package=&quot;...&quot; />   Spring Bean Management
Bean Scopes  singleton   Scopes a single bean definition to a single object instance per Spring IoC container. prototype   Scopes a single bean definition to any number of object instances. request   Scopes a single bean definition to the lifecycle of a single HTTP request.  session   Scopes a single bean definition to the lifecycle of a HTTP Session.  global session   Scopes a single bean definition to the lifecycle of a global HTTP Session. Typically only valid when used in a portlet context.
Singleton Bean
Prototype Beans Use @Scope(&quot;prototype&quot;) Caution: dependencies are resolved at instantiation time. It does NOT create  a new instance at runtime more than once.
Bean Scopes Contd.. As a rule of thumb, you should use the prototype scope for all beans that are stateful, while the singleton scope should be used for stateless beans. RequestContextListener is needed in web.xml for request/session scopes. Annotation:@Scope(&quot;request&quot;) @Scope(&quot;prototype&quot;)   Homework:  Singleton bean referring a prototype/request bean? @Qualifier, Method Injection.  Hate Homework? Stick to stateless beans. :)
Wiring Beans no No autowiring at all. Bean references must be defined via a ref element. This is the default. byName Autowiring by property name.  byType Allows a property to be autowired if there is exactly one bean of the property type in the container. If there is more than one, a fatal exception is thrown. constructor This is analogous to  byType , but applies to constructor arguments. autodetect Chooses  constructor  or  byType  through introspection of the bean class. 
Homework :) What wiring method is used with @Autowire annotation?  Other annotations you may find useful: @Required @Resource Also review the Spring annotation article: http://www.techferry.com/articles/spring-annotations.html
MVC - Model View Controller Better organization and code reuse.  Separation of Concern Can support multiple views
Spring MVC Code Demo .... Annotations: @Controller, @RequestMapping, @ModelAttribute, @PathVariable Spring DispatcherServlet config - just scan controllers   web.xml - Context loader listener to scan other components ResourceBundleMessageSource and <spring:message> tag    Reference: http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/mvc.html  @RequestMapping Details  Handler method arguments and Return Types
Pre-populate Model and Session Objects @Controller  @RequestMapping(&quot;/owners/{ownerId}/pets/{petId}/edit&quot;)  @SessionAttributes(&quot;pet&quot;)  public class EditPetForm {            @ModelAttribute(&quot;types&quot;)        public Collection<PetType> populatePetTypes() {              return this.clinic.getPetTypes();       }         @RequestMapping(method = RequestMethod.POST)       public String processSubmit(@ModelAttribute(&quot;pet&quot;) Pet pet, BindingResult result,                                                                       SessionStatus status) {          new PetValidator().validate(pet, result);           if (result.hasErrors()) {                return &quot;petForm&quot;;           }else {               this.clinic.storePet(pet);               status.setComplete();               return &quot;redirect:owner.do?ownerId=&quot; + pet.getOwner().getId();           }       }  }
Form Validation Code Demo ... BindingResult Validator.validate() <form:errors> tag    Alternative: Hibernate Validator can also be used for annotation based validation.   public class PersonForm {       @NotNull       @Size(max=64)       private String name;         @Min(0)       private int age;  } @RequestMapping(&quot;/foo&quot;)    public void processFoo(@Valid Foo foo) {       /* ... */      }
Unit Testing @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = { &quot;/spring-servlet-test.xml&quot; }) @Test Other useful Annotations: @DirtiesContext  @ExpectedException(SomeBusinessException.class) @Timed(millis=1000) @NotTransactional   
Spring Security Code Demo ... <sec:authorize> tag  Annotations: @PreAuthorize applicationContext-security.xml  DB Schema: Users, Authorities
Thank you and Questions?

More Related Content

PPT
Hibernate training
PPTX
Massively Scalable Applications - TechFerry
PDF
Spring annotation
DOCX
Spring annotations notes
PPTX
Spring core
PPT
Java Server Faces (JSF) - advanced
PDF
Create Your Own Framework by Fabien Potencier
PDF
Introduction to Spring MVC
Hibernate training
Massively Scalable Applications - TechFerry
Spring annotation
Spring annotations notes
Spring core
Java Server Faces (JSF) - advanced
Create Your Own Framework by Fabien Potencier
Introduction to Spring MVC

What's hot (20)

PPTX
Spring jdbc
PDF
Spring MVC Annotations
ODP
Dependency Injection, Zend Framework and Symfony Container
PPTX
2. 엔티티 매핑(entity mapping) 2 2 엔티티매핑 2-2-4. 식별자 자동 생성(@generated-value)4
PPTX
Spring FrameWork Tutorials Java Language
ODT
Types of Dependency Injection in Spring
PPT
AspMVC4 start101
PPT
C#/.NET Little Pitfalls
PPTX
Grails with swagger
PPT
Unified Expression Language
PPTX
Zend Studio Tips and Tricks
PPT
Spring Core
PPT
Spring talk111204
PDF
Sling Models Using Sightly and JSP by Deepak Khetawat
PPTX
Spring aop
PPS
Advance Java
PPTX
Spring mvc
KEY
IoC with PHP
PPTX
Dependency injection - the right way
Spring jdbc
Spring MVC Annotations
Dependency Injection, Zend Framework and Symfony Container
2. 엔티티 매핑(entity mapping) 2 2 엔티티매핑 2-2-4. 식별자 자동 생성(@generated-value)4
Spring FrameWork Tutorials Java Language
Types of Dependency Injection in Spring
AspMVC4 start101
C#/.NET Little Pitfalls
Grails with swagger
Unified Expression Language
Zend Studio Tips and Tricks
Spring Core
Spring talk111204
Sling Models Using Sightly and JSP by Deepak Khetawat
Spring aop
Advance Java
Spring mvc
IoC with PHP
Dependency injection - the right way
Ad

Similar to Spring training (20)

PDF
springtraning-7024840-phpapp01.pdf
PPTX
Spring IOC and DAO
PPTX
Poco Es Mucho: WCF, EF, and Class Design
PPT
Os Johnson
ODP
Annotation-Based Spring Portlet MVC
PPT
Ef Poco And Unit Testing
ODP
Intro To Spring Python
PPTX
ODP
Spring framework
PPTX
Real World Asp.Net WebApi Applications
PPTX
Spring from a to Z
PPTX
Spring 1 day program
PPTX
Spring framework
PPTX
DOCX
Spring review_for Semester II of Year 4
PPT
Introduction To ASP.NET MVC
PPT
PPT
Spring Framework
PPT
Spring framework
PDF
2-0. Spring ecosytem.pdf
springtraning-7024840-phpapp01.pdf
Spring IOC and DAO
Poco Es Mucho: WCF, EF, and Class Design
Os Johnson
Annotation-Based Spring Portlet MVC
Ef Poco And Unit Testing
Intro To Spring Python
Spring framework
Real World Asp.Net WebApi Applications
Spring from a to Z
Spring 1 day program
Spring framework
Spring review_for Semester II of Year 4
Introduction To ASP.NET MVC
Spring Framework
Spring framework
2-0. Spring ecosytem.pdf
Ad

Recently uploaded (20)

PDF
Approach and Philosophy of On baking technology
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPTX
Machine Learning_overview_presentation.pptx
PDF
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
PPTX
cloud_computing_Infrastucture_as_cloud_p
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
A comparative analysis of optical character recognition models for extracting...
PDF
Machine learning based COVID-19 study performance prediction
PPTX
Programs and apps: productivity, graphics, security and other tools
PPTX
Tartificialntelligence_presentation.pptx
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
August Patch Tuesday
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PPTX
OMC Textile Division Presentation 2021.pptx
PDF
Spectral efficient network and resource selection model in 5G networks
PPTX
SOPHOS-XG Firewall Administrator PPT.pptx
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Approach and Philosophy of On baking technology
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Machine Learning_overview_presentation.pptx
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
cloud_computing_Infrastucture_as_cloud_p
MIND Revenue Release Quarter 2 2025 Press Release
Building Integrated photovoltaic BIPV_UPV.pdf
A comparative analysis of optical character recognition models for extracting...
Machine learning based COVID-19 study performance prediction
Programs and apps: productivity, graphics, security and other tools
Tartificialntelligence_presentation.pptx
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
August Patch Tuesday
Reach Out and Touch Someone: Haptics and Empathic Computing
Unlocking AI with Model Context Protocol (MCP)
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
OMC Textile Division Presentation 2021.pptx
Spectral efficient network and resource selection model in 5G networks
SOPHOS-XG Firewall Administrator PPT.pptx
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx

Spring training

  • 1. Spring Training TechFerry Infotech Pvt. Ltd. (http://www.techferry.com/)
  • 2. Conversations Introduction to Spring Concepts: Annotations, MVC, IOC/DI, Auto wiring Spring Bean/Resource Management Spring MVC, Form Validations. Unit Testing Spring Security – Users, Roles, Permissions.  Code Demo CRUD using Spring, Hibernate, MySQL. Spring security example. REST/jQuery/Ajax example
  • 3. Spring - Introduction Exercise: What do we need in an enterprise application?   Database Access, Connection Pools? Transactions?  Security, Authentication, Authorization? Business Logic Objects? Workflow/Screen Flow? Messaging/emails? Service Bus? Concurrency/Scalability? Can somebody wire all the needed components? Do we have to learn everything before we can start?
  • 4. Hello Spring Spring is potentially a one-stop shop, addressing most infrastructure concerns of typical web applications so you focus only on your business logic. Spring is both comprehensive and modular use just about any part of it in isolation, yet its architecture is internally consistent. maximum value from your learning curve.
  • 5. What is Spring? Open source and lightweight web-application framework Framework for wiring the entire application Collection of many different components Reduces code and speeds up development   Spring is essentially a technology dedicated to enabling you to build applications using POJOs.
  • 6. Why Spring? Spring Enables POJO Programming  Application code does not depend on spring API’s Dependency Injection and Inversion of Control simplifies coding Promotes decoupling and re-usability   Features: Lightweight Inversion of Control (IoC) Aspect oriented (AOP) MVC Framework Transaction Management JDBC Ibatis / Hibernate
  • 8. What else Spring do? Spring Web Flow Spring Integration Spring Web-Services Spring MVC Spring Security Spring Batch Spring Social Spring Mobile       ... and let it ever expand ...
  • 9. Inversion of Control/Dependency Injection &quot;Don't call me, I'll call you.&quot;    IoC moves the responsibility for making things happen into the framework Eliminates lookup code from within the application Loose coupling, minimum effort and least intrusive mechanism 
  • 11. IOC/DI Non IOC Example: class MovieLister...   private MovieFinder finder;   public MovieLister() {     finder = new MovieFinderImpl();   } public interface MovieFinder {   List findAll(); } class MovieFinderImpl ... {   public List findAll() {     ...   } }
  • 12. IOC/DI IoC Example: DI exists in major two variants: Setter Injection              public class MovieLister {                 private MovieFinder movieFinder;                 public void setMovieFinder(MovieFinder movieFinder) {                     this.movieFinder = movieFinder;                 }         } Constructor Injection       public class MovieLister{ private MovieFinder movieFinder; public MovieLister(MovieFinder movieFinder) {     this.movieFinder = movieFinder; }       }
  • 13. Code Demo .... Annotations: @Component, @Service,  @Repository Annotation:  @Autowire web.xml - Context loader listener to scan components    <context:annotation-config />     <context:component-scan base-package=&quot;...&quot; />  Spring Bean Management
  • 14. Bean Scopes  singleton Scopes a single bean definition to a single object instance per Spring IoC container. prototype Scopes a single bean definition to any number of object instances. request Scopes a single bean definition to the lifecycle of a single HTTP request. session Scopes a single bean definition to the lifecycle of a HTTP Session.  global session Scopes a single bean definition to the lifecycle of a global HTTP Session. Typically only valid when used in a portlet context.
  • 16. Prototype Beans Use @Scope(&quot;prototype&quot;) Caution: dependencies are resolved at instantiation time. It does NOT create a new instance at runtime more than once.
  • 17. Bean Scopes Contd.. As a rule of thumb, you should use the prototype scope for all beans that are stateful, while the singleton scope should be used for stateless beans. RequestContextListener is needed in web.xml for request/session scopes. Annotation:@Scope(&quot;request&quot;) @Scope(&quot;prototype&quot;)   Homework: Singleton bean referring a prototype/request bean? @Qualifier, Method Injection. Hate Homework? Stick to stateless beans. :)
  • 18. Wiring Beans no No autowiring at all. Bean references must be defined via a ref element. This is the default. byName Autowiring by property name.  byType Allows a property to be autowired if there is exactly one bean of the property type in the container. If there is more than one, a fatal exception is thrown. constructor This is analogous to byType , but applies to constructor arguments. autodetect Chooses constructor or byType through introspection of the bean class. 
  • 19. Homework :) What wiring method is used with @Autowire annotation? Other annotations you may find useful: @Required @Resource Also review the Spring annotation article: http://www.techferry.com/articles/spring-annotations.html
  • 20. MVC - Model View Controller Better organization and code reuse. Separation of Concern Can support multiple views
  • 21. Spring MVC Code Demo .... Annotations: @Controller, @RequestMapping, @ModelAttribute, @PathVariable Spring DispatcherServlet config - just scan controllers  web.xml - Context loader listener to scan other components ResourceBundleMessageSource and <spring:message> tag   Reference: http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/mvc.html  @RequestMapping Details Handler method arguments and Return Types
  • 22. Pre-populate Model and Session Objects @Controller  @RequestMapping(&quot;/owners/{ownerId}/pets/{petId}/edit&quot;)  @SessionAttributes(&quot;pet&quot;)  public class EditPetForm {            @ModelAttribute(&quot;types&quot;)       public Collection<PetType> populatePetTypes() {              return this.clinic.getPetTypes();       }         @RequestMapping(method = RequestMethod.POST)       public String processSubmit(@ModelAttribute(&quot;pet&quot;) Pet pet, BindingResult result,                                                                       SessionStatus status) {         new PetValidator().validate(pet, result);           if (result.hasErrors()) {               return &quot;petForm&quot;;           }else {               this.clinic.storePet(pet);               status.setComplete();               return &quot;redirect:owner.do?ownerId=&quot; + pet.getOwner().getId();           }       }  }
  • 23. Form Validation Code Demo ... BindingResult Validator.validate() <form:errors> tag    Alternative: Hibernate Validator can also be used for annotation based validation.   public class PersonForm {       @NotNull       @Size(max=64)       private String name;         @Min(0)       private int age;  } @RequestMapping(&quot;/foo&quot;)    public void processFoo(@Valid Foo foo) {      /* ... */     }
  • 24. Unit Testing @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = { &quot;/spring-servlet-test.xml&quot; }) @Test Other useful Annotations: @DirtiesContext @ExpectedException(SomeBusinessException.class) @Timed(millis=1000) @NotTransactional  
  • 25. Spring Security Code Demo ... <sec:authorize> tag Annotations: @PreAuthorize applicationContext-security.xml DB Schema: Users, Authorities
  • 26. Thank you and Questions?

Editor's Notes

  • #5: You might choose to use Spring only to simplify use of JDBC, for example, or you might choose to use Spring to manage all your business objects.