Top Banner
67

The Future of Spring Dr. Mark Pollack Agenda Unifying Component Model New Web Application Architectures NoSQL & Big Data Deploy to Cloud or on.

Dec 24, 2015

Download

Documents

Florence Adams
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: The Future of Spring Dr. Mark Pollack Agenda  Unifying Component Model  New Web Application Architectures  NoSQL & Big Data Deploy to Cloud or on.
Page 2: The Future of Spring Dr. Mark Pollack Agenda  Unifying Component Model  New Web Application Architectures  NoSQL & Big Data Deploy to Cloud or on.

The Future of Spring

Dr. Mark Pollack

Page 3: The Future of Spring Dr. Mark Pollack Agenda  Unifying Component Model  New Web Application Architectures  NoSQL & Big Data Deploy to Cloud or on.

Agenda

Unifying Component Model New Web Application

Architectures NoSQL & Big Data

Deploy to Cloud or on

premise

NoSQL,Big Data

Web, Integration,

Batch

Page 4: The Future of Spring Dr. Mark Pollack Agenda  Unifying Component Model  New Web Application Architectures  NoSQL & Big Data Deploy to Cloud or on.

Remember this…?

4

Page 5: The Future of Spring Dr. Mark Pollack Agenda  Unifying Component Model  New Web Application Architectures  NoSQL & Big Data Deploy to Cloud or on.

Remember this?

5

Page 6: The Future of Spring Dr. Mark Pollack Agenda  Unifying Component Model  New Web Application Architectures  NoSQL & Big Data Deploy to Cloud or on.

Some things change…

6

Changes in version 0.9 (25.6.2003)----------------------------------•first public release since the version that came with the book "Expert One-on-One J2EE Design and Development”•following various unofficial 0.8 CVS snapshots

Page 7: The Future of Spring Dr. Mark Pollack Agenda  Unifying Component Model  New Web Application Architectures  NoSQL & Big Data Deploy to Cloud or on.

Some things stay the same

7

Changes in version 0.9 (25.6.2003)----------------------------------•first public release since the version that came with the book "Expert One-on-One J2EE Design and Development”•following various unofficial 0.8 CVS snapshots•log via Commons Logging•revised web framework•general tightening and polishing•new sample application "Petclinic"

Page 8: The Future of Spring Dr. Mark Pollack Agenda  Unifying Component Model  New Web Application Architectures  NoSQL & Big Data Deploy to Cloud or on.

Some things stay the same

8

“I believe that Spring is unique, for several reasons:

• It addresses important areas that many other popular frameworks don't

• Spring is both comprehensive and modular.

• Spring is designed from the ground up to help you write code that's easy to test.

• Spring is an increasingly important integration technology”

- Rod Johnson, TheServerSide.com, 2005

Page 9: The Future of Spring Dr. Mark Pollack Agenda  Unifying Component Model  New Web Application Architectures  NoSQL & Big Data Deploy to Cloud or on.

The Spring Stack

9

Page 10: The Future of Spring Dr. Mark Pollack Agenda  Unifying Component Model  New Web Application Architectures  NoSQL & Big Data Deploy to Cloud or on.

Spring – Unifying Component Model

10

Page 11: The Future of Spring Dr. Mark Pollack Agenda  Unifying Component Model  New Web Application Architectures  NoSQL & Big Data Deploy to Cloud or on.

SimpleObjectSimpleObjectsD

epen

denc

y In

ject

ion

(DI)

Aspect Orientation (AO

P)

Portable Service Abstractions

Remember This One?

Page 12: The Future of Spring Dr. Mark Pollack Agenda  Unifying Component Model  New Web Application Architectures  NoSQL & Big Data Deploy to Cloud or on.

SimpleObject

AnnotatedComponents

Inje

ctio

n An

nota

tions

Composable Stereotypes

Service-Oriented Annotations

An Annotated Perspective

Page 13: The Future of Spring Dr. Mark Pollack Agenda  Unifying Component Model  New Web Application Architectures  NoSQL & Big Data Deploy to Cloud or on.

A Typical Annotated Component

@Servicepublic class MyBookAdminService implements BookAdminService {

@Autowired public MyBookAdminService(AccountRepository ar) { … }

@Transactional public BookUpdate updateBook(Addendum addendum) { … }}

Page 14: The Future of Spring Dr. Mark Pollack Agenda  Unifying Component Model  New Web Application Architectures  NoSQL & Big Data Deploy to Cloud or on.

1. Composable Stereotype Model

• Powerful options for custom stereotypes

@Service@Scope("request")@Transactional(rollbackFor=Exception.class)@Retention(RetentionPolicy.RUNTIME)public @interface MyService {}

@MyServicepublic class BookAdminService { …}

Page 15: The Future of Spring Dr. Mark Pollack Agenda  Unifying Component Model  New Web Application Architectures  NoSQL & Big Data Deploy to Cloud or on.

2. Injection Annotations

• Spring's @Autowired & @Value versus JSR-330's @Inject

@Autowiredpublic MyBookAdminService(@Qualifier("myRepo") AccountRepository ar, @Value("#{systemProperties.databaseName}") String dbName) { …}

@Injectpublic MyBookAdminService(@Named("myRepo") AccountRepository ar) { …}

Page 16: The Future of Spring Dr. Mark Pollack Agenda  Unifying Component Model  New Web Application Architectures  NoSQL & Big Data Deploy to Cloud or on.

3. Service-Oriented Annotations

• E.g. declarative transactions & declarative scheduling

@Transactionalpublic BookUpdate updateBook(Addendum addendum) { …}

@Scheduled(cron = "0 0 12 * * ?")public void performTempFileCleanup() { …}

Page 17: The Future of Spring Dr. Mark Pollack Agenda  Unifying Component Model  New Web Application Architectures  NoSQL & Big Data Deploy to Cloud or on.

Example: Declarative Caching

• Based on a full-featured cache abstraction

@Cacheablepublic Owner loadOwner(int id);

@Cacheable(condition="name.length < 10")public Owner loadOwner(String name);

@CacheEvictpublic void deleteOwner(int id);

Page 18: The Future of Spring Dr. Mark Pollack Agenda  Unifying Component Model  New Web Application Architectures  NoSQL & Big Data Deploy to Cloud or on.

@RequestMapping(value = "/books/{id}", method = GET)

public Book findBook(@PathVariable("id") long id) {

return this.bookAdminService.findBook(id);

}

http://mybookstore.com/books/12345

Example: Spring MVC - @PathVariable

Page 19: The Future of Spring Dr. Mark Pollack Agenda  Unifying Component Model  New Web Application Architectures  NoSQL & Big Data Deploy to Cloud or on.

Example: Declarative Model Validation

public class Book { @NotNull @Past private Date releaseDate;}

@RequestMapping("/books/new")

public void newBook(@Valid Book book) { … }

• JSR-303 "Bean Validation" as the common ground

Page 20: The Future of Spring Dr. Mark Pollack Agenda  Unifying Component Model  New Web Application Architectures  NoSQL & Big Data Deploy to Cloud or on.

Example: Declarative Formatting

• Annotation-driven number and date formatting

public class Book { @NotNull @Past @DateTimeFormat(iso=ISO.DATE) private Date releaseDate;}

Page 21: The Future of Spring Dr. Mark Pollack Agenda  Unifying Component Model  New Web Application Architectures  NoSQL & Big Data Deploy to Cloud or on.

Bootstrapping Your Annotated Components

• Typical: a concise XML bean definition file– <context:component-scan base-package=”com.myapp”/>– @Repository / @Service / @Controller / @Configuration stereotype– compare: JPA persistence.xml with @Entity classes

• Alternative: AnnotationConfigApplicationContext– scan(basePackage)– register(componentClass)– register(configurationClass)

Page 22: The Future of Spring Dr. Mark Pollack Agenda  Unifying Component Model  New Web Application Architectures  NoSQL & Big Data Deploy to Cloud or on.

WebApplicationInitializer

/** * Servlet 3.0 based initializer, autodetected by Spring. */public class MyWebAppInitializer implements WebApplicationInitializer {

public void onStartup(ServletContext sc) throws ServletException {

// Create the 'root' Spring application context AnnotationConfigWebApplicationContext root =

new AnnotationConfigWebApplicationContext(); root.scan("com.mycompany.myapp"); root.register(FurtherConfig.class);

// Manages the lifecycle of the root application context sc.addListener(new ContextLoaderListener(root));

... }}

Page 23: The Future of Spring Dr. Mark Pollack Agenda  Unifying Component Model  New Web Application Architectures  NoSQL & Big Data Deploy to Cloud or on.

Configuration Classes

@Configuration

public class MyBookAdminConfig {

@Bean

public BookAdminService myBookAdminService() {

MyBookAdminService service = new MyBookAdminService();

service.setDataSource(bookAdminDataSource());

return service;

}

@Bean

public DataSource bookAdminDataSource() {

}

}

Page 24: The Future of Spring Dr. Mark Pollack Agenda  Unifying Component Model  New Web Application Architectures  NoSQL & Big Data Deploy to Cloud or on.

XML-Free JPA Setup

@Configuration

public class MyBookAdminConfig {

@Bean

public FactoryBean myEntityManagerFactoryBean() {

LocalContainerEntityManagerFactoryBean emfb = new LocalContainerEntityManagerFactoryBean();

emfb.setPackagesToScan(“com.mycompany.myapp”);

emfb.setDataSource(bookAdminDataSource());

return emfb;

}

@Bean

public DataSource bookAdminDataSource() { … }

}

Page 25: The Future of Spring Dr. Mark Pollack Agenda  Unifying Component Model  New Web Application Architectures  NoSQL & Big Data Deploy to Cloud or on.

Summary

• Spring's distinctive annotated component model– composable stereotype model– injection annotations– service-oriented annotations– flexible bootstrapping options– if desired: 100% XML-free deployment

Page 26: The Future of Spring Dr. Mark Pollack Agenda  Unifying Component Model  New Web Application Architectures  NoSQL & Big Data Deploy to Cloud or on.

• Why do we need new application architectures?

• What do they look like?

• How do I build these apps with Spring?

Application Architecture

Page 27: The Future of Spring Dr. Mark Pollack Agenda  Unifying Component Model  New Web Application Architectures  NoSQL & Big Data Deploy to Cloud or on.

Drivers of Change

Page 28: The Future of Spring Dr. Mark Pollack Agenda  Unifying Component Model  New Web Application Architectures  NoSQL & Big Data Deploy to Cloud or on.

User

expectations

Drivers of Change

New client

devices

Corporate

expectations

QoS• internet scale???• survive AWS outage

Hybrid is

inevitable

Data

Page 29: The Future of Spring Dr. Mark Pollack Agenda  Unifying Component Model  New Web Application Architectures  NoSQL & Big Data Deploy to Cloud or on.

From: server-side appsTo: smart clients and services

Page 30: The Future of Spring Dr. Mark Pollack Agenda  Unifying Component Model  New Web Application Architectures  NoSQL & Big Data Deploy to Cloud or on.

Client

Server

ViewGeneration

ViewGeneration ControllersControllers

Service LayerService Layer

RepositoriesRepositoriesChannelsChannels RDBMSRDBMS

CRUD

ApplicationServer

Browser

Browser-based

HTML Rendering

(progressive

enhancement)

Browser-based

HTML Rendering

(progressive

enhancement)

HTML HTTP

Page 31: The Future of Spring Dr. Mark Pollack Agenda  Unifying Component Model  New Web Application Architectures  NoSQL & Big Data Deploy to Cloud or on.

Client

Server

Service LayerService Layer

RepositoriesRepositoriesChannelsChannels RDBMSRDBMS

CRUD

Browser app orembedded in native

JSON HTTP & websockets

HTML5 & JS Engine

ControllersControllersDOMDOMClient-side modelClient-side model

events& notifications

web stgweb stg

Page 32: The Future of Spring Dr. Mark Pollack Agenda  Unifying Component Model  New Web Application Architectures  NoSQL & Big Data Deploy to Cloud or on.

Client

Cloud/PaaS

Service LayerService Layer

RepositoriesRepositoriesChannelsChannels RDBMSRDBMS

CRUD

Browser app orembedded in native

JSON HTTP & websockets

HTML5 & JS Engine

ControllersControllersDOMDOMClient-side modelClient-side model

events& notifications

web stgweb stg

ServiceService ServiceService ServiceService business / domain services

Page 33: The Future of Spring Dr. Mark Pollack Agenda  Unifying Component Model  New Web Application Architectures  NoSQL & Big Data Deploy to Cloud or on.

Client

PaaSCRUD

RepositoriesRepositoriesChannelsChannels RDBMSRDBMS

Browser app orembedded in native

JSON HTTP & websockets

HTML5 & JS Engine

ControllersControllersDOMDOMClient-side modelClient-side model

events& notifications

web stgweb stg

ServiceService ServiceService ServiceService business / domain services

Page 34: The Future of Spring Dr. Mark Pollack Agenda  Unifying Component Model  New Web Application Architectures  NoSQL & Big Data Deploy to Cloud or on.

Client

PaaS

Browser app orembedded in native

JSON HTTP & websockets

HTML5 & JS Engine

ControllersControllersDOMDOMClient-side modelClient-side model

events& notifications

web stgweb stg

ServiceService ServiceService ServiceService business / domain services

ServiceService ServiceService ServiceServiceplatform services,web APIsSQLSQL NoSQLNoSQL Other

Page 35: The Future of Spring Dr. Mark Pollack Agenda  Unifying Component Model  New Web Application Architectures  NoSQL & Big Data Deploy to Cloud or on.

HTML5(& native)

PaaS

JSON HTTP & websockets

HTML5 & JS Engine

events&

notifications

Applications

Services

Page 36: The Future of Spring Dr. Mark Pollack Agenda  Unifying Component Model  New Web Application Architectures  NoSQL & Big Data Deploy to Cloud or on.

Smart Clients

Page 37: The Future of Spring Dr. Mark Pollack Agenda  Unifying Component Model  New Web Application Architectures  NoSQL & Big Data Deploy to Cloud or on.

The Monty Hall Game

Page 38: The Future of Spring Dr. Mark Pollack Agenda  Unifying Component Model  New Web Application Architectures  NoSQL & Big Data Deploy to Cloud or on.

The Monty Hall Game

The Gray Mouse Lemur – Small, Furry, and Gray!http://www.factzoo.com/mammals/gray-mouse-lemur-small-furry-gray.html

Page 39: The Future of Spring Dr. Mark Pollack Agenda  Unifying Component Model  New Web Application Architectures  NoSQL & Big Data Deploy to Cloud or on.

The Monty Hall Game

Page 40: The Future of Spring Dr. Mark Pollack Agenda  Unifying Component Model  New Web Application Architectures  NoSQL & Big Data Deploy to Cloud or on.

The Monty Hall Game

Stick or Change?

Page 41: The Future of Spring Dr. Mark Pollack Agenda  Unifying Component Model  New Web Application Architectures  NoSQL & Big Data Deploy to Cloud or on.

• Cujo– curl

– wire

– when

– aop

• Clicks

Client-side code walkthrough and demo

$> demo

Page 42: The Future of Spring Dr. Mark Pollack Agenda  Unifying Component Model  New Web Application Architectures  NoSQL & Big Data Deploy to Cloud or on.

Service-side design

Page 43: The Future of Spring Dr. Mark Pollack Agenda  Unifying Component Model  New Web Application Architectures  NoSQL & Big Data Deploy to Cloud or on.

The frontline:SPAs, REST, (& WebSockets)

Page 44: The Future of Spring Dr. Mark Pollack Agenda  Unifying Component Model  New Web Application Architectures  NoSQL & Big Data Deploy to Cloud or on.

Apps, REST, & WebSocketsnativeapps

browser-based apps

App Store

(Web Apps) & Services

REST

SPA

ws:

Download

Interaction

Page 45: The Future of Spring Dr. Mark Pollack Agenda  Unifying Component Model  New Web Application Architectures  NoSQL & Big Data Deploy to Cloud or on.

• Spring MVC as the foundation

• Spring Data REST – Basic Entity Management via CRUD

– Builds on…

• Spring HATEOAS– Link Builder

– Resource Assembler

RESTful API design with Spring

Page 46: The Future of Spring Dr. Mark Pollack Agenda  Unifying Component Model  New Web Application Architectures  NoSQL & Big Data Deploy to Cloud or on.

Monty Hall Game Resource

47

POST /games201 CreatedLocation : /games/{id}

GET /games/{id}200 OK{status : “awaiting_initial_selection” links : [ { rel : “self”, href : “http://…/games/{id}” }, { rel : “doors”, href : “http://…/games/{id}/doors”}, { rel : “history”, href : “http://…/games/{id}/history”}]}

Page 47: The Future of Spring Dr. Mark Pollack Agenda  Unifying Component Model  New Web Application Architectures  NoSQL & Big Data Deploy to Cloud or on.

Monty Hall Door Resource

48

GET /games/{id}/doors200 OK{ doors : [ {status : “closed”, content : “unknown”, links : [ {rel : “self”, href : “http://…/games{id}/doors/1”}]}, {status : “closed”, content : “unknown”, links : [ {rel : “self”, href : “http://…/games{id}/doors/2”}]}, {status : “closed”, content : “unknown”, links : [ {rel : “self”, href : “http://…/games{id}/doors/3”}]} ], links : [ { rel : “self”, href : “http://…/games{id}/doors”} ] }

Page 48: The Future of Spring Dr. Mark Pollack Agenda  Unifying Component Model  New Web Application Architectures  NoSQL & Big Data Deploy to Cloud or on.

Monty Hall Door Resource

49

PATCH (PUT) /games/{id}/doors/{id} {“status” : “SELECTED”}200 OK{status : “SELECTED”, content : “unknown”, links : [ {rel : “self”, href : “http://…/games{id}/doors/1”}

PATCH (PUT) /games/{id}/doors/{id} {“status” : “OPENED”}200 OK{status : “OPENED”, content : “juergen”, links : [ {rel : “self”, href : “http://…/games{id}/doors/1”}

Page 49: The Future of Spring Dr. Mark Pollack Agenda  Unifying Component Model  New Web Application Architectures  NoSQL & Big Data Deploy to Cloud or on.

Design Pattern

controller

resourceassembler resource

domainobject

representation

Page 50: The Future of Spring Dr. Mark Pollack Agenda  Unifying Component Model  New Web Application Architectures  NoSQL & Big Data Deploy to Cloud or on.

• Spring MVC• Spring Hateoas

Code Walkthrough and Demo

51

$> demo

Page 51: The Future of Spring Dr. Mark Pollack Agenda  Unifying Component Model  New Web Application Architectures  NoSQL & Big Data Deploy to Cloud or on.

• Why do we need new data access solutions?

• What do they look like?

• How do I build these apps with Spring?

Data Access

Page 52: The Future of Spring Dr. Mark Pollack Agenda  Unifying Component Model  New Web Application Architectures  NoSQL & Big Data Deploy to Cloud or on.

Drivers of Change

Page 53: The Future of Spring Dr. Mark Pollack Agenda  Unifying Component Model  New Web Application Architectures  NoSQL & Big Data Deploy to Cloud or on.

The New Data Universe

54

Page 54: The Future of Spring Dr. Mark Pollack Agenda  Unifying Component Model  New Web Application Architectures  NoSQL & Big Data Deploy to Cloud or on.

The Data Revolution

55

Page 55: The Future of Spring Dr. Mark Pollack Agenda  Unifying Component Model  New Web Application Architectures  NoSQL & Big Data Deploy to Cloud or on.

Putting Data to Work

56

Page 56: The Future of Spring Dr. Mark Pollack Agenda  Unifying Component Model  New Web Application Architectures  NoSQL & Big Data Deploy to Cloud or on.

Spring Data Mission Statement

57

89% of all virtualized applications in the world run on VMware.

Gartner, December 2008“Provides a familiar and consistent

Spring-based programming model for Big Data, NoSQL, and relational stores while retaining store-specific features and capabilities.

Page 57: The Future of Spring Dr. Mark Pollack Agenda  Unifying Component Model  New Web Application Architectures  NoSQL & Big Data Deploy to Cloud or on.

• Consistency

• Accuracy– JPA != NoSQL

• Productivity– Template classes

– Object Mapping

– Repositories

• Horizontal integration– Spring Integration

– Spring Batch

– Gemfire 7.0

From there to here, from here to there, funny things are everywhere!”

58

Programming Model

Gemfire

Data Technologies

JPA/JDBC

• 60 releases this year

• SpringOne 2GX Release Train

• O’Reilly Book

Page 58: The Future of Spring Dr. Mark Pollack Agenda  Unifying Component Model  New Web Application Architectures  NoSQL & Big Data Deploy to Cloud or on.

Configuration

59

@Configuration@ComponentScan@EnableTransactionManagement@EnableJpaRepositoriespublic class JpaConfig {

@Bean public DataSource dataSource() { ... }

@Bean public PlatformTransactionManager transactionManager() { ... }}

@Configuration@ComponentScan@EnableMongoRepositoriespublic class MongoConfig extends AbstractMongoConfig {

@Override public Mongo mongo() throws Exception { … } @Override protected String getDatabaseName() { … }

}

Page 59: The Future of Spring Dr. Mark Pollack Agenda  Unifying Component Model  New Web Application Architectures  NoSQL & Big Data Deploy to Cloud or on.

Mapping

60

@Entity@Table(name = "Orders")public class Order {

@ManyToOne(optional = false) private Customer customer;

@OneToMany(cascade = CascadeType.ALL, orphanRemoval = true) @JoinColumn(name = "order_id") private Set<LineItem> lineItems = new HashSet<LineItem>();}

@Document(collection="Orders")public class Order {

@DBRef private Customer customer;

private Set<LineItem> lineItems = new HashSet<LineItem>();

...}

Page 60: The Future of Spring Dr. Mark Pollack Agenda  Unifying Component Model  New Web Application Architectures  NoSQL & Big Data Deploy to Cloud or on.

Repository

61

public interface ProductRepository extends CrudRepository<Product, Long>, QueryDslPredicateExecutor<Product> {

Page<Product> findByDescriptionContaining(String description, Pageable pageable);

@Query("select p from Product p where p.attributes[?1] = ?2") List<Product> findByAttributes(String attribute, String value);}

Page 61: The Future of Spring Dr. Mark Pollack Agenda  Unifying Component Model  New Web Application Architectures  NoSQL & Big Data Deploy to Cloud or on.

• Big Data problems are also integration problems

Horizontal Integration

62

Collect Transform RT Analysis Ingest Batch Analysis Distribute Use

Spring Integration & Data

Spring Hadoop + Batch

Spring MVCTwitter Search& GardenhoseTwitter Search& Gardenhose RedisRedis

Page 62: The Future of Spring Dr. Mark Pollack Agenda  Unifying Component Model  New Web Application Architectures  NoSQL & Big Data Deploy to Cloud or on.

• Spring Integration • Spring Data

Code Walkthrough and Demo

$> demo

Page 63: The Future of Spring Dr. Mark Pollack Agenda  Unifying Component Model  New Web Application Architectures  NoSQL & Big Data Deploy to Cloud or on.

What’s next?

Page 64: The Future of Spring Dr. Mark Pollack Agenda  Unifying Component Model  New Web Application Architectures  NoSQL & Big Data Deploy to Cloud or on.

Spring Framework – Next version themes

• Java SE 8 – SE 8 language features are a natural fit for the Spring programming model

• Java EE 7– Support for JCache, JMS 2.0, JPA 2.1, Bean Validation 1.1

• Annotation-driven message listening and annotation-driven events within the application

• Websockets• Removal of deprecated classes• System requirements: Java SE 6+, Java EE 5+

Page 65: The Future of Spring Dr. Mark Pollack Agenda  Unifying Component Model  New Web Application Architectures  NoSQL & Big Data Deploy to Cloud or on.

Spring Integration, Batch, Data

• Unified platform to address existing + new integration markets

Shared Data Integration Framework

•Combine Spring Integration, Batch, Data via single Modular data flow API and DSL•Common adapters, serializers, deserializers•Batch job scheduling, composition of data processing pipelines

Spring Integration

•Enterprise integration•Enterprise messaging•Channel abstraction•Adapters

Spring Data

•Relational and NoSQL•Object mapping•CRUD, repository•Now also Hadoop

Spring Batch

•Batch job scheduling•Parsers, mappers•Readers, writers•Partial processing etc.

Page 66: The Future of Spring Dr. Mark Pollack Agenda  Unifying Component Model  New Web Application Architectures  NoSQL & Big Data Deploy to Cloud or on.

• Simplifying Java development • Helping enterprise developers with their biggest

challenges

Spring has always been about…

67

Page 67: The Future of Spring Dr. Mark Pollack Agenda  Unifying Component Model  New Web Application Architectures  NoSQL & Big Data Deploy to Cloud or on.

Thank You!