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

Spring forward: an introduction to Spring boot and Thymeleaf for ICS developers

LetsConnect
September 16, 2019

Spring forward: an introduction to Spring boot and Thymeleaf for ICS developers

The world of a ICS developer is moving fast. Customers rethinking platforms and solutions. Spring Boot makes it easy to create stand-alone, production-grade Spring based Applications that you can “just run”. In combination with Thymeleaf can it be good alternative for your Domino applications. In this session I give an introduction of Spring Boot and Thymeleaf and how to get started. I will show the differences and similarities between Spring Boot in combination with Thymeleaf and XPages. I will explain the challenges I faced when moving an application.

LetsConnect

September 16, 2019
Tweet

More Decks by LetsConnect

Other Decks in Technology

Transcript

  1. Spring forward
    an introduction to Spring boot and Thymeleaf for
    developers
    Frank van der Linden
    Full stack Developer

    View Slide

  2. Social Connections 15 Munich, September 16-18 2019

    View Slide

  3. Social Connections 15 Munich, September 16-18 2019
    About me
    • Freelance Full stack developer
    • Owner of elstar IT
    • Curious of new technology
    • IBM Champion 2013, 2014, 2017, 2018 and 2019
    • HCL Master 2019

    View Slide

  4. Social Connections 15 Munich, September 16-18 2019
    How to proceed
    • What is Spring boot and Thymeleaf
    • How to start
    • Syntax
    • Security
    • Bonus - new possibilities

    View Slide

  5. Social Connections 15 Munich, September 16-18 2019
    Spring Forward Starter - demo project
    https://github.com/flinden68/spring-forward-starter

    View Slide

  6. Social Connections 15 Munich, September 16-18 2019
    What is Spring boot and Thymeleaf

    View Slide

  7. Social Connections 15 Munich, September 16-18 2019

    View Slide

  8. Social Connections 15 Munich, September 16-18 2019
    Spring boot
    • Open source, Pivotal is coordinating the releases
    • Spring boot creates Spring (Java) based applications
    • Embedded Tomcat makes it ‘just’ run everywhere
    • Auto configure as much as possible
    • Built in metrics and health checks
    • Easy to configure with YAML or property file
    • Very good documentation and code examples
    • Fast creation of REST api’s

    View Slide

  9. Social Connections 15 Munich, September 16-18 2019
    Runs everywhere
    • With Embedded Tomcat as default the jar ‘just run’
    • More choices of embedded web server, like Netty
    • Will run on Docker
    • Will run on Cloud Foundry, like IBM Cloud or Pivotal on Azure
    • Tomcat can by excluding to run it on Websphere Application
    Server, Tomcat or WildFly (a.k.a JBoss)
    • Even on Domino as OSGi plugin, http://hasselba.ch/blog/?
    p=2589

    View Slide

  10. Social Connections 15 Munich, September 16-18 2019
    Thymeleaf
    • Is a template engine, like XPages or Freemarker
    • Based on Java and HTML5
    • Very strict, or template will break
    • Full Spring framework support
    • Extensible with dialects
    • Full (and extensible) internationalisation support.
    • Reusable fragments, like Custom Controls
    • Extensive documentation

    View Slide

  11. Social Connections 15 Munich, September 16-18 2019
    How to start

    View Slide

  12. Social Connections 15 Munich, September 16-18 2019
    How to start
    • Install Gradle or Maven
    • Move over to start.spring.io
    • Or use the Starter in IntelliJ
    • Fill all the fields and select the required projects (full
    version)
    • Generate project
    • Download zip, unzip and add to Git repository.
    • Open project in favourite IDE, run ‘mvn clean install’
    • Start coding

    View Slide

  13. Social Connections 15 Munich, September 16-18 2019
    Wizard in IntelliJ

    View Slide

  14. Social Connections 15 Munich, September 16-18 2019
    Spring boot setup
    minimal YAML property file

    View Slide

  15. Social Connections 15 Munich, September 16-18 2019
    Thymeleaf setup
    add to pom.xml

    View Slide

  16. Social Connections 15 Munich, September 16-18 2019
    How it works together

    View Slide

  17. Social Connections 15 Munich, September 16-18 2019
    Syntax

    View Slide

  18. Social Connections 15 Munich, September 16-18 2019
    Spring boot syntax
    endpoint to return an object as JSON
    endpoint to return a thymeleaf template

    View Slide

  19. Social Connections 15 Munich, September 16-18 2019
    Component scan
    • Component scan will scan all the packages for @Service,
    @Controller, @Repository and more @Component(s)
    • @Autowired will glue everything together

    View Slide

  20. Social Connections 15 Munich, September 16-18 2019
    Thymeleaf syntax
    • Include the th namespace to the page
    • Every html element attribute has a th:…. Equivalent.
    • Variable Expressions: ${...}
    • Selection Variable Expressions: *{...}
    • Message Expressions: #{...}
    • Link URL Expressions: @{...}

    View Slide

  21. Social Connections 15 Munich, September 16-18 2019
    Namespace

    View Slide

  22. Social Connections 15 Munich, September 16-18 2019
    Thymeleaf attributes

    View Slide

  23. Social Connections 15 Munich, September 16-18 2019
    Variable Expressions

    View Slide

  24. Social Connections 15 Munich, September 16-18 2019
    Selection Variable Expressions

    View Slide

  25. Social Connections 15 Munich, September 16-18 2019
    Message Expressions

    View Slide

  26. Social Connections 15 Munich, September 16-18 2019
    Link URL Expressions
    resource links
    links in on a page

    View Slide

  27. Social Connections 15 Munich, September 16-18 2019
    Global objects

    View Slide

  28. Social Connections 15 Munich, September 16-18 2019
    Fragments (1)

    View Slide

  29. Social Connections 15 Munich, September 16-18 2019
    Fragments (2)
    fragment code
    use it multiple times

    View Slide

  30. Social Connections 15 Munich, September 16-18 2019
    Attachments
    • Forget the UploadedFile provided by IBM, learn
    MultipartFile
    • MultipartFile has lots of similarities with UploadedFile, but
    easier to use. Less code to achieve the same

    View Slide

  31. Social Connections 15 Munich, September 16-18 2019
    Security

    View Slide

  32. Social Connections 15 Munich, September 16-18 2019
    Spring Security
    • Framework for Authentication and Authorisation
    • Prevention of clickjacking, CORS, cross site request
    forgery
    • Integrates with Spring Boot and Thymeleaf
    • Customisable to the bone
    • Support for Basic Authentication, SAML2, oAuth and
    more.

    View Slide

  33. Social Connections 15 Munich, September 16-18 2019
    Configuration
    CORS prevention
    add to pom.xml

    View Slide

  34. Social Connections 15 Munich, September 16-18 2019
    Spring security in Thymeleaf
    add to pom.xml
    add namespace

    View Slide

  35. Social Connections 15 Munich, September 16-18 2019
    Bonus - new possibilities

    View Slide

  36. Social Connections 15 Munich, September 16-18 2019
    Lombok
    • Forget Getters and Setters
    • Forget toString, hashCode and equals
    • One @Annotations rules the all (@Data or @Getter and
    @Setter)
    • Add logging by @annotations (@Log4j2 or @Slf4j)

    View Slide

  37. Social Connections 15 Munich, September 16-18 2019
    Lombok
    add to pom.xml
    add @Data
    using the build in logging

    View Slide

  38. Social Connections 15 Munich, September 16-18 2019
    Swagger
    • Part of Open API Specification, since v3
    • Documentation of API’s
    • Playground for testing
    • Add annotation to generate the documentation
    dynamically

    View Slide

  39. Social Connections 15 Munich, September 16-18 2019
    Swagger
    add to pom.xml
    add a configuration
    add annotation to endpoint

    View Slide

  40. Social Connections 15 Munich, September 16-18 2019
    Jenkins
    • With Jenkins you can build automatically the application
    • …But also do quality control, do load tests and even
    deploy.
    • JenkinsFile should be in the root of the GIT Repository
    • Groovy is the language for JenkinsFile

    View Slide

  41. Social Connections 15 Munich, September 16-18 2019
    Jenkins file

    View Slide

  42. Social Connections 15 Munich, September 16-18 2019
    Questions

    View Slide

  43. Social Connections 15 Munich, September 16-18 2019
    Reach out to me
    @flinden68
    https://www.elstarit.nl
    [email protected]
    https://nl.linkedin.com/in/flinden68
    https://github.com/flinden68

    View Slide

  44. Social Connections 15 Munich, September 16-18 2019
    Resources
    •Spring Initializr
    •http://start.spring.io/
    •Thymeleaf documentation
    •http://www.thymeleaf.org/
    •Spring Boot
    • https://projects.spring.io/spring-boot/
    •Lombok
    • https://projectlombok.org/
    •Jenkins
    • https://jenkins.io/

    View Slide

  45. Social Connections 15 Munich, September 16-18 2019
    Resources
    •Swagger
    •http://swagger.io
    •Thymeleaf documentation
    •http://www.thymeleaf.org/
    •Maven
    • https://maven.apache.org/
    •Gradle
    • https://gradle.org/
    •Spring Forward Starter
    • https://github.com/flinden68/spring-forward-starter

    View Slide

  46. Social Connections 15 Munich, September 16-18 2019

    View Slide

  47. View Slide