CONFIGURING A SPRING DEVELOPMENT ENVIRONMENT

Similar documents
Spring Interview Questions

SPRING MOCK TEST SPRING MOCK TEST I

Fast Track to Spring 3 and Spring MVC / Web Flow

Desarrollo de Aplicaciones Web Empresariales con Spring 4

Spring Framework 2.0 New Persistence Features. Thomas Risberg

JAVA COURSES. Empowering Innovation. DN InfoTech Pvt. Ltd. H-151, Sector 63, Noida, UP

Spring framework was initially written by Rod Johnson and was first released under the Apache 2.0 license in June 2003.

Spring & Hibernate. Knowledge of database. And basic Knowledge of web application development. Module 1: Spring Basics

JVA-117A. Spring-MVC Web Applications

Struts: Struts 1.x. Introduction. Enterprise Application

Introduction to Spring Framework: Hibernate, Web MVC & REST

com Spring + Spring-MVC + Spring-Boot + Design Pattern + XML + JMS Hibernate + Struts + Web Services = 8000/-

ADVANCED JAVA TRAINING IN BANGALORE

Developing Spring based WebSphere Portal application using IBM Rational Application Developer

Introduction to Spring Framework: Hibernate, Spring MVC & REST

Introduction to Spring 5, Spring MVC and Spring REST

Java EE 7: Back-End Server Application Development

JVA-117E. Developing RESTful Services with Spring

Fast Track. Evaluation Copy. to Spring 3.x. on Eclipse/Tomcat. LearningPatterns, Inc. Courseware. Student Guide

Enterprise Java Development using JPA, Hibernate and Spring. Srini Penchikala Detroit JUG Developer Day Conference November 14, 2009

Introduction to Web Application Development Using JEE, Frameworks, Web Services and AJAX

Spring Framework 2.5: New and Notable. Ben Alex, Principal Software Engineer, SpringSource

Spring 2.5 on the Way to 3.0

Web Application Development Using Spring, Hibernate and JPA

Advanced Web Systems 5- Designing Complex Applications. -The IOC Pattern -Light Weight Container. A. Venturini

Comparative Analysis of EJB3 and Spring Framework

POJOs to the rescue. Easier and faster development with POJOs and lightweight frameworks

Oracle - Developing Applications for the Java EE 7 Platform Ed 1 (Training On Demand)

Spring Persistence. with Hibernate PAUL TEPPER FISHER BRIAN D. MURPHY

Spring Professional v5.0 Exam

Deccansoft Software Services. J2EE Syllabus

Web Application Development Using Spring, Hibernate and JPA

Fast Track to Spring 3 and Spring Web Flow 2.1

Specialized - Mastering Spring 4.2

Java J Course Outline

SPRING FRAMEWORK ARCHITECTURE

Fast Track to EJB 3.0 and the JPA Using JBoss

Sitesbay.com. A Perfect Place for All Tutorials Resources. Java Projects C C++ DS Interview Questions JavaScript

Call: JSP Spring Hibernate Webservice Course Content:35-40hours Course Outline

Java EE 6: Develop Web Applications with JSF

CO Java EE 7: Back-End Server Application Development

Web Application Development Using Spring, Hibernate and JPA

Chapter 13. Hibernate with Spring

EJB ENTERPRISE JAVA BEANS INTRODUCTION TO ENTERPRISE JAVA BEANS, JAVA'S SERVER SIDE COMPONENT TECHNOLOGY. EJB Enterprise Java

Developing Applications with Java EE 6 on WebLogic Server 12c

~ Ian Hunneybell: CBSD Revision Notes (07/06/2006) ~

Spring Framework. Christoph Pickl

J2EE - Version: 25. Developing Enterprise Applications with J2EE Enterprise Technologies

is Introduction to Spring 5 and JPA 2

Exam Questions 1Z0-895

1 Markus Eisele, Insurance - Strategic IT-Architecture

The Spring Framework: Overview and Setup

Business Logic and Spring Framework

Spring, a J2EE extension framework. JUGS presentation by Philipp H. Oser

This course is intended for Java programmers who wish to write programs using many of the advanced Java features.

Web Application Development Using JEE, Enterprise JavaBeans and JPA

Courses For Event Java Advanced Summer Training 2018

Inversion of Control (IoC) and Dependency Injection (DI) in Spring

Seam 3. Pete Muir JBoss, a Division of Red Hat

Java Spring Hibernate Interview Questions And Answers For

Web Application Development Using JEE, Enterprise JavaBeans and JPA

Java EE Application Assembly & Deployment Packaging Applications, Java EE modules. Model View Controller (MVC)2 Architecture & Packaging EJB Module

Development of E-Institute Management System Based on Integrated SSH Framework

A Lightweight Java Container

COURSE DETAILS: CORE AND ADVANCE JAVA Core Java

Page 1

Java EE 6: Develop Business Components with JMS & EJBs

Enterprise JavaBeans, Version 3 (EJB3) Programming

Java EE Architecture, Part Two. Java EE architecture, part two 1

Lightweight J2EE Framework

Specialized - Mastering JEE 7 Web Application Development

CHAPTER 6 VALIDATION

Call: Core&Advanced Java Springframeworks Course Content:35-40hours Course Outline

Enterprise AOP With the Spring Framework

JVA-163. Enterprise JavaBeans

Type of Classes Nested Classes Inner Classes Local and Anonymous Inner Classes

What is it? What does it do?

2005, Cornell University

NetBeans IDE Field Guide

Java- EE Web Application Development with Enterprise JavaBeans and Web Services

CMP 436/774. Introduction to Java Enterprise Edition. Java Enterprise Edition

JAVA MICROSERVICES. Java Language Environment. Java Set Up. Java Fundamentals. Packages. Operations

Pro JPA 2. Mastering the Java Persistence API. Apress* Mike Keith and Merrick Schnicariol

JAVA. 1. Introduction to JAVA

Spring Today and Tomorrow

Java SE7 Fundamentals

Improve and Expand JavaServer Faces Technology with JBoss Seam

Chapter 1 Introducing EJB 1. What is Java EE Introduction to EJB...5 Need of EJB...6 Types of Enterprise Beans...7

Fast Track to Java EE

Data Access on Tourism Resources Management System Based on Spring JDBC Jifu Tong

Snowdrop 1.0 User Guide

J2EE Interview Questions

Java EE 6 & Spring: A Lover s Quarrel. Derrick Kittler Mauricio Maltron Leal Vamsi Chemitiganti

This is the first part of a multi-article series. For part 2 please see: Dependency Injection in Java EE 6 - Part 2

Migrating traditional Java EE applications to mobile

Skyway Builder User Guide (BETA 1)

7 Reasons to use Spring. Arjen Poutsma SpringSource

Introduction to Spring

Java Enterprise Edition

Modular Java Applications with Spring, dm Server and OSGi

Transcription:

Module 5 CONFIGURING A SPRING DEVELOPMENT ENVIRONMENT The Spring Framework > The Spring framework (spring.io) is a comprehensive Java SE/Java EE application framework > Spring addresses many aspects of Java/Java EE application development, and it can help you to build high-quality, high-performance applications more quickly. > The heart of the Spring framework is a lightweight IoC container that is able to add enterprise services to simple Java objects declaratively.

The Spring Framework > Spring makes extensive use of an excellent programming methodology AOP to provide these services to its components. > Within the Spring IoC container s scope, components are also called beans. > The Spring framework itself incorporates many design patterns, including the GoF object-oriented patterns and Sun s core Java EE patterns. > By using the Spring framework, you will use industry best practices to design and implement your applications. What is Spring? > Spring is a lightweight dependency injection and aspectoriented container and framework. > Lightweight Spring is lightweight in terms of both size and overhead: The Spring Framework can be distributed in a single JAR file that weighs in at just over 2.5 MB. The processing overhead required by Spring is negligible. Spring is nonintrusive: objects in a Spring-enabled application often have no dependencies on Springspecific classes.

What is Spring? > Spring is a lightweight dependency injection and aspectoriented container and framework. > Dependency Injection Spring promotes loose coupling through a technique known as dependency injection (DI). > When DI is applied, objects are passively given their dependencies instead of creating or looking for dependent objects for themselves. What is Spring? > Spring is a lightweight dependency injection and aspectoriented container and framework. > Aspect-oriented Spring comes with rich support for aspect-oriented programming (AOP) that enables cohesive development by separating application business logic from system services (such as auditing and transaction management). Application objects do what they re supposed to do perform business logic and nothing more. They are not responsible for other system concerns, such as logging or transactional support.

What is Spring? > Spring is a lightweight dependency injection and aspectoriented container and framework. > Container Spring is a container in the sense that it contains and manages the lifecycle and configuration of application objects. In Spring, you can declare how each of your application objects should be created, how they should be configured, and how they should be associated with each other. What is Spring? > Spring is a lightweight dependency injection and aspectoriented container and framework. > Framework Spring makes it possible to configure and compose complex applications from simpler components. In Spring, application objects are composed declaratively, typically in an XML file. Spring also provides much infrastructure functionality (transaction management, persistence framework integration, etc.), leaving the development of application logic to you.

Spring Framework History > Started 2002 Rod Johnson and Juergen Holler Expert One-on-one J2EE Design and Development Spring 1.0 released on March 2004 Interface21, Spring source, now spring io > Current version (2014) 4.0 Spring==Java EE Application Server? > Spring is NOT a Java EE application server Integrates with Java EE application server Can work without a server > Spring does not replace a server > Spring provides application services Spring can replace services traditionally provided by Java EE application servers Make the application independent of server runtime

Spring Framework Mission Statement > Java EE should be easier to use > It is best to program to interfaces, rather than classes. Spring reduces the complexity cost of using interfaces to zero. > JavaBeans offer a great way of configuring applications. > OO design is more important than any implementation technology, such as Java EE. > Checked exceptions are overused in Java. A platform shouldn't force you to catch exceptions you're unlikely to be able to recover from. > Testability is essential Spring should help make your code easier to test. Introducing Spring s Modules > The Spring Framework consists of features organized into about 20 modules.

Introducing Spring s Modules > The Core and Beans modules provide the fundamental parts of the framework, including the IoC and Dependency Injection features. > The BeanFactory is a sophisticated implementation of the factory pattern. > It removes the need for programmatic singletons and allows you to decouple the configuration and specification of dependencies from your actual program logic. Introducing Spring s Modules > Means to access objects in a framework-style manner that is similar to a JNDI registry. > Advanced Spring IoC container: ApplicationContext. > Adds features such as internationalization support, eventbased communication, and resource loading

Introducing Spring s Modules > The Expression Language module provides a powerful expression language for querying and manipulating an object graph at runtime. It is an extension of the unified expression language (unified EL) as specified in the JSP 2.1 specification. > The language supports setting and getting property values, property assignment, method invocation, accessing the context of arrays, collections and indexers, logical and arithmetic operators, named variables, and retrieval of objects by name from Spring's IoC container Introducing Spring s Modules > This module establishes an aspect-oriented programming framework, which is referred to as Spring AOP. > AOP is another of Spring s fundamental concepts besides IoC.

Introducing Spring s Modules > This module supports both programmatic and declarative approaches for you to manage transactions. These can be used to add transaction capability to your simple Java objects. Introducing Spring s Modules > This module defines an abstract layer on top of the native JDBC API, which supports programming against JDBC in a template-based approach that dispenses with boilerplate code.

Introducing Spring s Modules > This module integrates popular object/relational mapping frameworks such as Hibernate, JDO, TopLink, ibatis, and JPA into Spring. Introducing Spring s Releases > XML schema based configuration: In Spring 1.x, XML bean configuration files only support DTDs, and everything you can define within them must be through the <bean> element. Spring 2.0 supports XML schema based configuration, which allows you to use Spring s new tags. As a result, your bean configuration files can be much simpler and clearer.

Introducing Spring s Releases > Annotation-driven configuration: As a complement to XML-based configuration, Spring 2.0 supports annotation-driven configuration in certain modules, such as @Required, @Transactional, @PersistenceContext, and @PersistenceUnit Introducing Spring s Releases > New Spring AOP approach: The classic AOP usage in Spring 1.x is through a set of proprietary Spring AOP APIs. Spring 2.0 introduces a brand-new AOP approach through writing POJOs with either AspectJ annotations or XML schema based configuration.

Introducing Spring s Releases > Easier transaction declaration: Declaring transactions in Spring 2.0 is much easier. You can use the new Spring AOP approach to declare transaction, or apply @Transactional annotations with the <tx:annotation-driven> tag. > JPA support: Spring 2.0 introduces support for the Java Persistence API in its ORM module. > Form tag library: Spring 2.0 introduces a new form tag library to make developing forms in Spring MVC easier. Introducing Spring s Releases > Asynchronous JMS support: Spring 1.x only supports receiving JMS messages synchronously through JmsTemplate. Spring 2.0 adds support for asynchronous JMS reception through message-driven POJOs. > Scripting language support: Spring 2.0 supports implementing beans with the scripting languages JRuby, Groovy, and BeanShell.

Introducing Spring s Releases > Annotation-driven configuration: Spring 2.5 supports more, including @Autowired and the JSR-250 annotations @Resource, @PostConstruct, and @PreDestroy. > Component scanning: Spring 2.5 can automatically detect your components with particular stereotype annotations from the classpath without manual configuration. Introducing Spring s Releases > AspectJ load-time weaving support: Spring 2.5 supports weaving AspectJ aspects into Spring IoC container at load time, so you use Aspect aspects beyond the reach of Spring AOP s support. > Annotation-based web controllers: Spring 2.5 supports a new annotation-based approach to web controller development. It can auto-detect your controller classes with the @Controller annotation, and also information you configure in @RequestMapping, @RequestParam, and @ModelAttribute annotations.

New Features & Enhancements in Spring 3.0 > Java 5 The entire framework code has been revised to take advantage of Java 5 features like generics, varargs and other language improvements > Improved documentation: The Spring reference documentation has also substantially been updated to reflect all of the changes and new features for Spring 3.0. New Features & Enhancements in Spring 3.0 > New module organization and build system Modules have been revised and are now managed separately with one source-tree per module jar: org.springframework.aop org.springframework.beans org.springframework.context org.springframework.context.support org.springframework.expression org.springframework.instrument org.springframework.jdbc org.springframework.jms org.springframework.orm org.springframework.oxm org.springframework.test org.springframework.transaction org.springframework.web org.springframework.web.portlet...

New Features & Enhancements in Spring 3.0 > Spring Expression Language > IoC enhancements/java based bean metadata > General-purpose type conversion system and field formatting system > Object to XML mapping functionality (OXM) moved from Spring Web Services project > Comprehensive REST support > @MVC additions including @CookieValue and @RequestHeader, to pull values from cookies and request headers, respectively > Declarative model validation > Embedded database support > Support for JSR-330 dependency injection specification Installing the Spring Framework > The Spring framework s installation is very simple. > You can simply download the Spring framework 2.5 or 3 release in ZIP format and extract it to a directory of your choice to complete the installation. > Before you install the Spring framework, you should have JDK installed on your machine. > Spring 2.5 requires JDK 1.4 or higher. You are strongly recommend that you install JDK 1.5 or higher so that you can use features such as annotations, autoboxing/unboxing, varargs, type-safe collections, and for-each loops.

Installing Spring > http://spring.io/projects Setting Up a Spring Project > We will use SpringSource Tool Suite 3.6.3.RELEASE

Setting Up a Spring Project > Create a Maven Project Setting Up a Spring Project > Open pom.xml and insert the following dependency <dependency> <groupid>org.springframework</groupid> <artifactid> spring-context </artifactid> <version>4.1.4.release</version> </dependency>

Setting Up a Spring Project import org.godel.domain.circle; import org.springframework.context.applicationcontext; import org.springframework.context.support.classpathxmlapplicationcontext; public class TestSpring { public static void main(string[] args) { ConfigurableApplicationContext context = new ClassPathXmlApplicationContext( "spring-config.xml"); Circle circle = (Circle) context.getbean("unitcircle"); System.out.println(circle); context.close(); } } Setting Up a Spring Project package org.godel.test; import org.godel.domain.circle; import org.springframework.context.applicationcontext; import org.springframework.context.support.classpathxmlapplicationcontext; public class TestSpring { public static void main(string[] args) { ApplicationContext context = new ClassPathXmlApplicationContext( "spring-config.xml"); Circle circle = context.getbean("unitcircle",circle.class); System.out.println(circle); } }

Setting Up a Spring Project > Edit Spring XML config file: <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:schemalocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> <bean id="unitcircle" class="org.godel.domain.circle"> <property name="radius" value="1.0"/> <property name="x" value="0.0"/> <property name="y" value="0.0"/> </bean> </beans> > Run the test code: Container Overview > Your application classes are combined with configuration metadata so that after the ApplicationContext is created and initialized, you have a fully configured and executable system or application.

Container Overview > Several implementations of the ApplicationContext interface are supplied out-of-the-box with Spring. > In standalone applications it is common to create an instance of ClassPathXmlApplicationContext or FileSystemXmlApplicationContext. > While XML has been the traditional format for defining configuration metadata you can instruct the container to use Java annotations or code as the metadata format by providing a small amount of XML configuration to declaratively enable support for these additional metadata formats. Instantiating a container > Instantiating a Spring IoC container is straightforward. > The location path or paths supplied to an ApplicationContext constructor are actually resource strings that allow the container to load configuration metadata from a variety of external resources such as the local file system, from the Java CLASSPATH ApplicationContext context = ); new ClassPathXmlApplicationContext( new String[] { } "services.xml", "dao.xml"

Composing XML-based configuration metadata > It can be useful to have bean definitions span multiple XML files. > Each individual XML configuration file represents a logical layer or module in your architecture. <beans> <import resource="services.xml"/> <import resource="resources/messagesource.xml"/> <import resource="/resources/themesource.xml"/> <bean id="bean1" class="..."/> <bean id="bean2" class="..."/> </beans>