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

Spring Data, Hypermedia and the Cloud

Spring Data, Hypermedia and the Cloud

Build REST Services with Spring Data & Spring Boot and run them locally, in a Docker container, on Lattice, Cloud Foundry or simply anywhere you want.

Christoph Strobl

September 24, 2015
Tweet

More Decks by Christoph Strobl

Other Decks in Programming

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/ Spring Data, Hypermedia and the Cloud Christoph Strobl, Pivotal Software Inc. @stroblchristoph
  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
  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
  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 Modules 4 Commons Neo4j Gemfire JPA Solr Elasticsearch REST Cassandra Couchbase Redis MongoDB Community
 modules Core
 modules Aerospike Hazelcast Crate Incubating KeyValue
  5. 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/ 5 Today we’ll have a look at… Spring Boot App
  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/ 6 “Spring Boot makes it easy to create Spring-powered, production-grade applications and services with absolute minimum fuss. The Spring Boot Team
  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/ One Slide App @SpringBootApplication public class StoreApp { ! public static void main(String[] args) { SpringApplication.run(StoreApp.class, args); } ! ! ! ! ! } 7 Page<Store> findByAddressLocationNear(Point location, Distance distance, Pageable pageable); interface StoreRepository extends PagingAndSortingRepository<Store, String> { ! ! }
  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/ § Hypermedia 8 Hypermedia is Coming image source:
 terrordesigners.com
  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/ Hypermedia Presentation of data and navigation controls at the same time 9
  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/ Spring Data REST 10 HATEOAS JSON HAL JSON Schema GET PUT POST PATCH Conditional ALPS Repositories Projections Resource http
  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/ Spring Data REST 11 @SpringBootApplication public class StoreApp { ! public static void main(String[] args) { SpringApplication.run(StoreApp.class, args); } ! interface StoreRepository extends PagingAndSortingRepository<Store, String> { ! ! } } Page<Store> findByAddressLocationNear(Point location, Distance distance, Pageable pageable); @RestResource(rel = "by-location") <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-rest</artifactId>
  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/ Let’s try this local… 12 $> mvn spring-boot:run <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin>
  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/ 14 image source:
 terrordesigners.com The Cloud 
 is waiting! image source: idigitaltimes.com
  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/ 15 “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
  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/ Run on Docker 16 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"] <plugin> <groupId>com.spotify</groupId> <artifactId>docker-maven-plugin</artifactId> <version>0.2.12</version> <configuration> <imageName>cstrobl/${project.artifactId}</imageName> 
 <dockerDirectory>src/main/docker<dockerDirectory>
 ... $> mvn package docker:build $> docker run -p 8080:8080 -t cstrobl/spring-data-rest-starbucks
  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
  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/ 18 “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
  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/ Run on Lattice 19 $> mvn package docker:build $> docker push cstrobl/spring-data-rest-starbucks $> ltc create starbucks cstrobl/spring-data-rest-starbucks --memory-mb=0
 $> ltc scale starbucks 2
  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
  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/ 21 “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
  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/ Run on Pivotal Cloud Foundry 22 $> 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
  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
  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/ 24 Go to start.spring.io 
 get Spring Boot with Spring Data 
 and deploy on
 Cloud Foundry, Docker and Lattice
 or simply anywhere you want!
  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/ Resources (alphabetical) § docker.com § hub.docker.com § lattice.cf § mongodb.org § projects.spring.io/spring-boot 25 § projects.spring.io/spring-data § run.pivotal.io § start.spring.io § vagrantup.com § virtualbox.org