Intro to Spring

15
Intro to Spring CJUG - January 2013

description

Intro to Spring. CJUG - January 2013. What is Spring?. “The Spring framework provides central transaction control of various objects.” - PowerPoint PPT Presentation

Transcript of Intro to Spring

Page 1: Intro to Spring

Intro to Spring

CJUG - January 2013

Page 2: Intro to Spring

What is Spring?

• “The Spring framework provides central transaction control of various objects.”

• This means that any number of diverse systems, platforms, environments can be centrally managed – very appealing in today’s complicated development stack environment.

Page 3: Intro to Spring

How does Spring do it?

• Spring controls instantiation of all the objects and passes a Spring reference to these objects using various DI – Dependency Injection techniques like getter/setter injection, and constructor injection (aka IoC - Inversion of Control).

Page 4: Intro to Spring

Any other benefits?

• Hot swapping, efficient testing, faster coding, and does not require complex JNDI code!

• Spring has layered architecture. Use what you need and leave you don't need now.

• Spring Enables POJO Programming, thus POJO programming enables continuous integration and testability.

• Dependency Injection and Inversion of Control Simplifies JDBC

• Open source and no vendor lock-in.

Page 5: Intro to Spring

Spring Features• Spring is lightweight when it comes to size, processing overhead and transparency

(basic version is around 1Meg.• Loose coupling is achieved in Spring using Inversion of Control. The objects give their

dependencies instead of creating or looking for dependent objects.• Spring supports Aspect oriented programming and enables cohesive development by

separating application business logic from system services.• Spring contains and manages the life cycle and configuration of application objects.• Spring comes with MVC web application framework, built on core Spring functionality.

This framework is highly configurable via strategy interfaces, and accommodates multiple view technologies like JSP, Velocity, Tiles, iText, and POI. But other frameworks can be easily used instead of Spring MVC Framework.

• Spring framework provides a generic abstraction layer for transaction management. This allowing the developer to add the pluggable transaction managers, and making it easy to demarcate transactions without dealing with low-level issues. Spring's transaction support is not tied to J2EE environments and it can be also used in container less environments.

• The JDBC abstraction layer of the Spring offers a meaningful exception hierarchy, which simplifies the error handling strategy. Integration with Hibernate, JDO, and iBATIS: Spring provides best Integration services with Hibernate, JDO and iBATIS

Page 6: Intro to Spring

Spring MVC

• Spring MVC operates via 4 key steps…

Page 7: Intro to Spring

Spring JPetstore MVC Sample• Based on today’s schedule, we only have enough time to review a quick Spring

sample. We will use the CJUG Reference Implementation a fully functional Sandbox for many Java technologies. Spring provides JPetstore sample app.

Page 8: Intro to Spring

Spring JPetstore MVC Sample• Starting Spring Tool Source, you need to start up the

tcServer

Page 9: Intro to Spring

Spring JPetstore MVC Sample• Test out the example by opening Firefox and loading up a

few sample pages (example: owner)

Page 10: Intro to Spring

Spring JPetstore MVC Sample• In the web.xml, implement Spring MVC first with the Spring

“DispatcherServlet”

Page 11: Intro to Spring

Spring JPetstore MVC Sample• In the web.xml, add any additional XML files spring needs.

Page 12: Intro to Spring

Spring JPetstore MVC Sample• The web.xml petclinic servlet will automatically

look for the petclinic-servlet.xml file

Page 13: Intro to Spring

Spring JPetstore MVC Sample• Found Owner Controller…

Page 14: Intro to Spring

Spring JPetstore MVC Sample• Handle View Resolving…

Page 15: Intro to Spring

Spring JPetstore MVC Sample• Controller redirect to owners…