Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Christoph Strobl on Spring Data & Hypermedia

Christoph Strobl on Spring Data & Hypermedia

More Decks by Enterprise Java User Group Austria

Other Decks in Technology

Transcript

  1. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under a

    Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
    Christoph Strobl, Pivotal Software Inc.
    @stroblchristoph
    Spring Data, Hypermedia and the Cloud

    View full-size slide

  2. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under a

    Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
    2

    View full-size slide

  3. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under a

    Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
    3
    “Spring Data provides a familiar and consistent
    Spring based programming model
    retaining store specific features
    and capabilities.
    O.Gierke

    View full-size slide

  4. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under a

    Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
    Spring Data
    4
    Abstraction
    relational non-relational
    JDBC*
    MongoDB Neo4j
    JPA*
    Redis
    Couchbase Cassandra Solr
    Spring Data

    View full-size slide

  5. Core
    KeyValue
    Gemfire
    JPA
    Solr
    Elasticsearch Cassandra
    Couchbase
    Redis
    MongoDB
    Community

    modules
    Core

    modules
    Neo4j
    REST
    Foundational Store modules Web APIs

    View full-size slide

  6. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under a

    Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
    The anatomy of a Spring Data module
    6
    where needed
    where needed
    where reasonable
    Templates
    Object mapping
    Repositories
    Spring Container Integration
    CDI
    Support

    View full-size slide

  7. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under a

    Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
    7
    Today we’ll have a look at…
    Spring Boot App

    View full-size slide

  8. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under a

    Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
    8
    “Spring Boot makes it easy to create
    Spring-powered, production-grade
    applications and services with absolute
    minimum fuss.
    The Spring Boot Team

    View full-size slide

  9. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under a

    Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
    One Slide App
    @SpringBootApplication
    public class StoreApp {
    !
    public static void main(String[] args) {
    SpringApplication.run(StoreApp.class, args);
    }
    !
    !
    !
    !
    !
    }
    9
    Page findByAddressLocationNear(Point location, Distance distance, Pageable pageable);
    interface StoreRepository extends PagingAndSortingRepository {
    !
    !
    }

    View full-size slide

  10. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under a

    Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
    § Hypermedia
    10
    Hypermedia is Coming
    image source:

    terrordesigners.com

    View full-size slide

  11. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under a

    Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
    Hypermedia
    Presentation of data and navigation controls at the same time
    11

    View full-size slide

  12. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under a

    Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
    Spring Data REST
    12
    HATEOAS
    JSON
    HAL
    JSON Schema
    GET
    PUT
    POST
    PATCH
    Conditional
    ALPS
    Repositories
    Projections
    Resource
    http

    View full-size slide

  13. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under a

    Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
    Spring Data REST
    13
    @SpringBootApplication
    public class StoreApp {
    !
    public static void main(String[] args) {
    SpringApplication.run(StoreApp.class, args);
    }
    !
    interface StoreRepository extends PagingAndSortingRepository {
    !
    !
    }
    }
    Page findByAddressLocationNear(Point location, Distance distance, Pageable pageable);
    @RestResource(rel = "by-location")
    org.springframework.boot
    spring-boot-starter-data-rest

    View full-size slide

  14. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under a

    Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
    Let’s try this local…
    14
    $> mvn spring-boot:run

    org.springframework.boot
    spring-boot-maven-plugin

    View full-size slide

  15. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under a

    Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
    16
    image source:

    terrordesigners.com
    The Cloud 

    is waiting!
    image source: idigitaltimes.com

    View full-size slide

  16. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under a

    Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
    17
    “Docker is an open platform for building, shipping
    and running distributed applications. It gives
    programmers, development teams and
    operations engineers the common toolbox they
    need to take advantage of the distributed and
    networked nature of modern applications.

    !
    docker.com

    View full-size slide

  17. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under a

    Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
    Run on Docker
    18
    FROM java:8
    VOLUME /tmp
    ADD spring-data-rest-starbucks.jar app.jar
    RUN bash -c 'touch /app.jar'
    ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar", "/app.jar"]

    com.spotify
    docker-maven-plugin
    0.2.12

    cstrobl/${project.artifactId} 

    src/main/docker

    ...
    $> mvn package docker:build
    $> docker run -p 8080:8080 -t cstrobl/spring-data-rest-starbucks

    View full-size slide

  18. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under a

    Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
    19

    View full-size slide

  19. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under a

    Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
    20
    “Lattice aspires to make clustering containers
    easy. It packages components from Cloud
    Foundry to provide a cloud native platform for
    individual developers and small teams.

    !
    lattice.cf

    View full-size slide

  20. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under a

    Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
    Run on Lattice
    21
    $> mvn package docker:build
    $> docker push cstrobl/spring-data-rest-starbucks
    $> ltc create starbucks cstrobl/spring-data-rest-starbucks --memory-mb 1024

    $> ltc scale starbucks 2

    View full-size slide

  21. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under a

    Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
    22

    View full-size slide

  22. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under a

    Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
    23
    “Pivotal Cloud Foundry is a Platform as a Service
    that supplies developers with a ready-to-use
    cloud computing environment and application
    services, all hosted by virtualized servers on your
    existing public and private infrastructure.
    !
    pivotal.io

    View full-size slide

  23. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under a

    Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
    Run on Pivotal Cloud Foundry
    24
    $> mvn package
    $> cf push starbucks -p target/spring-data-rest-starbucks.jar --no-start
    $> cf bind-service starbucks mongo
    $> cf start starbucks

    $> cf scale starbucks -i 2 -m 512M

    View full-size slide

  24. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under a

    Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
    25

    View full-size slide

  25. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under a

    Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
    26
    Go to start.spring.io 

    get Spring Boot with Spring Data 

    and deploy on

    Cloud Foundry, Docker and Lattice

    or simply anywhere you want!

    View full-size slide

  26. Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under a

    Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
    Resources (alphabetical)
    § docker.com
    § hub.docker.com
    § lattice.cf
    § mongodb.org
    § projects.spring.io/spring-boot
    27
    § projects.spring.io/spring-data
    § run.pivotal.io
    § start.spring.io
    § vagrantup.com
    § virtualbox.org

    View full-size slide