The Future of Spring
Dr. Mark Pollack
Agenda
Unifying Component Model New Web Application
Architectures NoSQL & Big Data
Deploy to Cloud or on
premise
NoSQL,Big Data
Web, Integration,
Batch
Remember this…?
4
Remember this?
5
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
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"
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
The Spring Stack
9
Spring – Unifying Component Model
10
SimpleObjectSimpleObjectsD
epen
denc
y In
ject
ion
(DI)
Aspect Orientation (AO
P)
Portable Service Abstractions
Remember This One?
SimpleObject
AnnotatedComponents
Inje
ctio
n An
nota
tions
Composable Stereotypes
Service-Oriented Annotations
An Annotated Perspective
A Typical Annotated Component
@Servicepublic class MyBookAdminService implements BookAdminService {
@Autowired public MyBookAdminService(AccountRepository ar) { … }
@Transactional public BookUpdate updateBook(Addendum addendum) { … }}
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 { …}
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) { …}
3. Service-Oriented Annotations
• E.g. declarative transactions & declarative scheduling
@Transactionalpublic BookUpdate updateBook(Addendum addendum) { …}
@Scheduled(cron = "0 0 12 * * ?")public void performTempFileCleanup() { …}
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);
@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
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
Example: Declarative Formatting
• Annotation-driven number and date formatting
public class Book { @NotNull @Past @DateTimeFormat(iso=ISO.DATE) private Date releaseDate;}
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)
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));
... }}
Configuration Classes
@Configuration
public class MyBookAdminConfig {
@Bean
public BookAdminService myBookAdminService() {
MyBookAdminService service = new MyBookAdminService();
service.setDataSource(bookAdminDataSource());
return service;
}
@Bean
public DataSource bookAdminDataSource() {
…
}
}
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() { … }
}
Summary
• Spring's distinctive annotated component model– composable stereotype model– injection annotations– service-oriented annotations– flexible bootstrapping options– if desired: 100% XML-free deployment
• Why do we need new application architectures?
• What do they look like?
• How do I build these apps with Spring?
Application Architecture
Drivers of Change
User
expectations
Drivers of Change
New client
devices
Corporate
expectations
QoS• internet scale???• survive AWS outage
Hybrid is
inevitable
Data
From: server-side appsTo: smart clients and services
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
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
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
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
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
HTML5(& native)
PaaS
JSON HTTP & websockets
HTML5 & JS Engine
events&
notifications
Applications
Services
Smart Clients
The Monty Hall Game
The Monty Hall Game
The Gray Mouse Lemur – Small, Furry, and Gray!http://www.factzoo.com/mammals/gray-mouse-lemur-small-furry-gray.html
The Monty Hall Game
The Monty Hall Game
Stick or Change?
• Cujo– curl
– wire
– when
– aop
• Clicks
Client-side code walkthrough and demo
$> demo
Service-side design
The frontline:SPAs, REST, (& WebSockets)
Apps, REST, & WebSocketsnativeapps
browser-based apps
App Store
(Web Apps) & Services
REST
SPA
ws:
Download
Interaction
• 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
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”}]}
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”} ] }
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”}
Design Pattern
controller
resourceassembler resource
domainobject
representation
• Spring MVC• Spring Hateoas
Code Walkthrough and Demo
51
$> demo
• Why do we need new data access solutions?
• What do they look like?
• How do I build these apps with Spring?
Data Access
Drivers of Change
The New Data Universe
54
The Data Revolution
55
Putting Data to Work
56
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.
• 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
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() { … }
}
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>();
...}
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);}
• 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
• Spring Integration • Spring Data
Code Walkthrough and Demo
$> demo
What’s next?
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+
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.
• Simplifying Java development • Helping enterprise developers with their biggest
challenges
Spring has always been about…
67
Thank You!