Spring MVC introduction HVA

22
Spring MVC Spring MVC Introduction

description

Quick introduction to Spring MVC for the HvA

Transcript of Spring MVC introduction HVA

Page 1: Spring MVC introduction HVA

Spring MVC

Spring MVCIntroduction

Page 2: Spring MVC introduction HVA

Spring MVC

Peter Maas ~ Works at Finalist IT Group. 70% Developer, 20% Architect and 10% CTO Board. Techniques used daily include Java/JEE, Spring, Hibernate, JSP. Passionate about scripting language for the JVM like Groovy and JRuby.

[email protected] ☄ maas-frensch.com/peter/

Page 3: Spring MVC introduction HVA

Spring MVC

Introduction to Spring MVC & Web Flow

Page 4: Spring MVC introduction HVA

Spring MVC

Spring ~ A Layered Java/JEE application framework. The most complete lightweight container, providing centralized, automated configuration and wiring of your application objects.

Spring

Page 5: Spring MVC introduction HVA

Spring MVC

Why Spring (I)

Key reasons

To provide a non-invasive programming model. As far as possible, application code should be decoupled from the framework.

To provide a superior solution to in-house infrastructure, so that developers can focus on delivering business value rather than solving generic problems.

To make developing enterprise applications as simple as possible, but enhancing, rather than sacrificing, power.

Page 6: Spring MVC introduction HVA

Spring MVC

Why Spring (II)

Page 7: Spring MVC introduction HVA

Spring MVC

<bean id="myRespository" class="com.finalist.MyRepositoryImpl"/><bean id="myService" class="com.finalist.MyServiceImpl"> <property name="maxResults" value="10"/> <property name="myRespository" ref="myRespository"/></bean>

Equals

myRepository = new MyRepositoryImpl();myService = new MyServiceImpl();

myService.setMyRepository(myRepository);myService.setMaxResults(10);

Spring basics

Page 8: Spring MVC introduction HVA

Spring MVC

<bean id="myRespository" class="com.finalist.MyRepositoryImpl"/><bean id="myService" class="com.finalist.MyServiceImpl"> <constructor-arg index="0" value="10"/> <constructor-arg index="1" ref="myRespository"/></bean>

Equals

myRepository = new MyRepositoryImpl();myService = new MyServiceImpl(10, myRepository);

Spring basics (II)

Page 9: Spring MVC introduction HVA

Spring MVC

Demo I ~ Basics of Spring

Demo I

Page 10: Spring MVC introduction HVA

Spring MVC

Integration

Services

WebDomainModel

User Interface

Typical SpringMVC Architecture

Spring MVC territory

Business logic

Connections to exernal systems (database,

webservices)

Page 11: Spring MVC introduction HVA

Spring MVC

MVC

Actor

View

Model

Controller

request

response

Page 12: Spring MVC introduction HVA

Spring MVC

Controller ~ Controllers interpret user input and transform such input into a sensible model which will be represented to the user by the view.

Controller

Page 13: Spring MVC introduction HVA

Spring MVC

public interface Controller {

/** * Process the request and return a * ModelAndView object which the DispatcherServlet * will render. */ ModelAndView handleRequest( HttpServletRequest request, HttpServletResponse response) throws Exception;

}

If you find yourself implementing the

controller interface you're probable doing

stuff the hard way!

Controller Interface

Page 14: Spring MVC introduction HVA

Spring MVC

«interface»Controller

AbstractController

SimpleFormController AbstractWizardFormController

ParameterizableViewController

BaseCommandController

AbstractFormController

AbstractCommandController

MultiActionController

UrlFilenameViewController

Controllers

Page 15: Spring MVC introduction HVA

Spring MVC

Model

Model ~ The domain-spec ific representation of the information on which the application operates.

List<SearchResult> results = new ArrayList<SearchResult>();

model.addObject("searchResults", results);

List<SearchResult> r = (List<SearchResult>)model.get("searchResults");

Page 16: Spring MVC introduction HVA

Spring MVC

View

View ~ Renders the model into a form suitable for interaction, typically a user interface element. Multiple views can exist for a single model for different purposes.

Page 17: Spring MVC introduction HVA

Spring MVC

view

RedirectView

InternalResourceView

AbstractJasperReportsView

AbstractTemplateView

AbstractView

AbstractExcelView

AbstractUrlBasedView

AbstractExcelView

AbstractPDFView

AbstractXsltView

AbstractJExcelView ...

...

JstlView

TilesView

Views

TilesJstlView

Page 18: Spring MVC introduction HVA

Spring MVC

Handlers ~ map incoming web requests to appropriate handlers.

<bean id="handlerMapping" class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping" />

or

<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"> <property name="urlMap"> <map> <entry key="/hello" value-ref="helloworldController" /> </map> </property></bean>

Handlers

Page 19: Spring MVC introduction HVA

Spring MVC

Demo II ~ Putting it all to work, making a simple "Hello World" Spring MVC application.

Demo II

Page 20: Spring MVC introduction HVA

Spring MVC

Demo II ~ Classpath essentials

spring-webmvc.jarcommons-logging.jarlogkit.jarspring-beans.jarspring-context.jaraopalliance.jarspring-core.jarspring-support.jarspring-web.jarlog4j.jar

Page 21: Spring MVC introduction HVA

Spring MVC

More to come ~ Complex forms, Binding, Validation, Interceptors, International isat ion, Webflow, Ajax ...

Page 22: Spring MVC introduction HVA

Spring MVC

Multicast / RMI Cache replication

Application servers (web)

Database cluster

Backoffice &cron jobs

internet

JDBC JDBC

internet

signon.vpro.nl

REST (https)

REST (https)

belbios

Firewall & Loadbalancer

Active Directory

LDAP

MMBase

SOAP (http)

NFS

XML

3rd party systems(NEBO/DONNA)

scp