670 likes | 798 Views
The Future of Spring. Dr. Mark Pollack. Agenda. Deploy to Cloud or on premise. Unifying Component Model New Web Application Architectures NoSQL & Big Data. NoSQL, Big Data. Core Model. Web, Integration, Batch. Remember this…?. Remember this?. Some things change….
E N D
The Future of Spring Dr. Mark Pollack
Agenda Deploy to Cloud or on premise • Unifying Component Model • New Web Application Architectures • NoSQL & Big Data NoSQL, Big Data CoreModel Web, Integration, Batch
Some things change… • 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 CVSsnapshots
Some things stay the same • 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 • “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
Remember This One? Simple Objects Simple Object Dependency Injection (DI) Aspect Orientation (AOP) Portable Service Abstractions
An Annotated Perspective AnnotatedComponents Simple Object Injection Annotations Composable Stereotypes Service-Oriented Annotations
A Typical Annotated Component @Service publicclass 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 {} @MyService public class BookAdminService { … }
2. Injection Annotations Spring's @Autowired & @Value versus JSR-330's @Inject @Autowired public MyBookAdminService(@Qualifier("myRepo") AccountRepository ar, @Value("#{systemProperties.databaseName}") String dbName) { … } @Inject public MyBookAdminService(@Named("myRepo") AccountRepository ar) { … }
3. Service-Oriented Annotations E.g. declarative transactions & declarative scheduling @Transactional public BookUpdate updateBook(Addendum addendum) { … } @Scheduled(cron = "0 0 12 * * ?") public void performTempFileCleanup() { … }
Example: Declarative Caching Based on a full-featured cache abstraction @Cacheable public Owner loadOwner(int id); @Cacheable(condition="name.length < 10") public Owner loadOwner(String name); @CacheEvict publicvoid deleteOwner(int id);
@RequestMapping(value = "/books/{id}", method = GET) public Book findBook(@PathVariable("id") long id) { return this.bookAdminService.findBook(id); } Example: Spring MVC - @PathVariable http://mybookstore.com/books/12345
Example: Declarative Model Validation publicclass 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 publicclass 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. */ publicclass MyWebAppInitializer implements WebApplicationInitializer { publicvoid 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 publicclass MyBookAdminConfig { @Bean public BookAdminService myBookAdminService() { MyBookAdminService service = new MyBookAdminService(); service.setDataSource(bookAdminDataSource()); return service; } @Bean public DataSource bookAdminDataSource() { … } }
XML-Free JPA Setup @Configuration publicclass 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
Application Architecture • Why do we need new application architectures? • What do they look like? • How do I build these apps with Spring?
Drivers of Change User expectations • Data • New client • devices • QoS • internet scale??? • survive AWS outage • Corporate • expectations • Hybrid is • inevitable
Client Browser-based HTML Rendering (progressive enhancement) Browser HTML HTTP View Generation Controllers Application Server Service Layer Channels Repositories RDBMS Server CRUD
Client HTML5 & JS Engine Browser app or embedded in native Client-side model web stg JSON HTTP & websockets events & notifications Service Layer DOM Controllers Channels Repositories RDBMS Server CRUD
Client HTML5 & JS Engine Browser app or embedded in native Client-side model web stg business / domain services JSON HTTP & websockets events & notifications Service Layer DOM Controllers Cloud/ PaaS Service Service Service Channels Repositories RDBMS CRUD
Client HTML5 & JS Engine Browser app or embedded in native Client-side model web stg business / domain services JSON HTTP & websockets events & notifications DOM Controllers Service Service Service PaaS CRUD Channels Repositories RDBMS
Client HTML5 & JS Engine Browser app or embedded in native Client-side model web stg business / domain services JSON HTTP & websockets events & notifications DOM Controllers Service Service Service Service Service Service platform services, web APIs SQL NoSQL PaaS Other
HTML5 & JS Engine Applications HTML5 (& native) JSON HTTP & websockets events & notifications Services PaaS
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 Stick or Change?
Client-side code walkthrough and demo • Cujo • curl • wire • when • aop • Clicks $> demo
Apps, REST, & WebSockets native apps App Store (Web Apps) & Services REST ws: SPA Download Interaction browser-based apps
RESTful API design with Spring • Spring MVC as the foundation • Spring Data REST • Basic Entity Management via CRUD • Builds on… • Spring HATEOAS • Link Builder • Resource Assembler
Monty Hall Game Resource POST /games 201 Created Location : /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 GET /games/{id}/doors 200 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 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 resource assembler resource controller representation domain object
Code Walkthrough and Demo • Spring MVC • Spring Hateoas $> demo