80 likes | 185 Views
Introduction to The Spring Framework Lightweight Enterprise Java Development. Dustin Schultz dustin.schultz@utah.edu. What is the Spring Framework?. “Lightweight” Enterprise Java Development Framework Helps you with “boilerplate” code (verbose code to accomplish something small)
E N D
Introduction to The Spring FrameworkLightweight Enterprise Java Development Dustin Schultz dustin.schultz@utah.edu
What is the Spring Framework? • “Lightweight” Enterprise Java Development Framework • Helps you with “boilerplate” code (verbose code to accomplish something small) • Dependency Injection – don’t call me, I’ll call you • Promotes loosely coupled development • A container to manage your objects
Lightweight • What does lightweight mean? • Originally it referred to being lightweight as compared to Enterprise Java Beans (EJB) • Additionally, it refers to how the Spring Framework can be used in parts • spring-core – The core, Dependency Injection, etc • spring-jdbc – Java Database Connectivity Support • spring-struts – Struts Framework Support • spring-web – Web Development Support (JSP, etc) • spring-orm – Object Relational Mapping Support (Hibernate, etc) • spring-aop – Aspect Oriented Programming Support • spring-test – Unit Testing Support • spring-oxm – Marshalling/Unmarshalling Support (JAXB, etc) • spring-jms – Java Messaging Support • Many more!
Boilerplate Reduction • Boilerplate code is frequent, verbose, code needed in order to accomplish something small. • Boilerplate Reduction = Simplification • JDBC is a great example of this • http://www.vaannila.com/spring/spring-jdbc-tutorial-1.html
Dependency Injection 1 (DI) • Enterprise development involves a lot of dependencies • This was originally one of Spring’s large selling points but Spring is now so much more. • Hollywood Principle – Don’t call me, I’ll call you • A form of Inversion of Control (IoC) • You give up control of instantiation/lookup to Spring
Dependency Injection 2 (DI) • Instead of “calling me” Object foo =FooFactory.getFoo(); • “I’ll call you” privateObject foo; publicvoidsetFoo(Object foo){ this.foo= foo; }
Container - ApplicationContext • ApplicationContextis a Object or “Bean” factory on steroids. • Instantiates your beans and adds additional functionality like post processors • Spring manages your objects • From instantiation to destruction • You hardly ever use the ‘new’ keyword anymore • “Singleton” • Lazy initialization
Coding Walkthrough • Goal: build a simple application that says hello in several languages utilizing Spring • If you use git: git clone git://git.bmi.utah.edu/swe-series/spring-intro.git • http://git.bmi.utah.edu/swe-series/spring-intro/archive-tarball/master