#engageug Spring forward: an introduction to Spring boot and Thymeleaf Frank van der Linden, elstar IT Full stack Developer 1 Engage 2018
#engageug Me • Freelance Full stack Java developer • Owner of elstar IT • Curious of new technology • IBM Champion 2013, 2014, 2017 and 2018 2
#engageug How to proceed • What is Spring boot and Thymeleaf • Similarities and differences • Runs everywhere • How to start • Syntax • Security • New possibilities 3
#engageug What is Spring boot and Thymeleaf 4
#engageug Spring Ecosystem 5
#engageug Spring boot • Open source, Pivotal is coordinating. • 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 6
#engageug Thymeleaf • Is a template engine • 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 of Custom Controls • Extensive documentation 7
#engageug Similarities and differences 8
#engageug 9 XPages Spring Boot/Thymeleaf Configure Faces-config @Autowired Endpoints Need work or SmartNSF very strong support Security Built-in Need Spring Security Add-ons Lots of 3rd party add-on Thanks to OpenNTF Lots of 3rd party add-on Deployment Runs on Domino Runs everwhere Build Pain of the Domino Designer Maven/Gradle build out-of-the box IDE DDE (Windows) for OSGi plugins almost every IDE Almost every IDE, like Netbeans, Eclipse, IntelliJ and more (Windows, Linux, MacOS)
#engageug Runs everywhere 10
#engageug Runs everywhere • With Embedded Tomcat as default the jar ‘just run’ • More choices of embedded web server, in the future also OpenLiberty • 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) 11
#engageug How to start 12
#engageug 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 13
#engageug 14 Wizard in IntelliJ
#engageug Spring boot setup 15 minimal YAML file
#engageug Thymeleaf setup 16 add to pom.xml
#engageug How it works together 17
#engageug Syntax 18
#engageug Spring boot syntax 19 endpoint to return an object as JSON endpoint to return a thymeleaf template
#engageug Component scan • Component scan will scan all the packages for @Service, @Controller, @Repository and more @Component(s) • @Autowired will glue everything together 20
#engageug 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: @{...} 21
#engageug Namespace 22 <html lang="en" xmlns:th="http://www.thymeleaf.org">
#engageug Thymeleaf attributes 23
#engageug Variable Expressions 24
#engageug Selection Variable Expressions 25
#engageug Message Expressions 26
#engageug Link URL Expressions 27 resource links links in on a page
#engageug Global objects 28
#engageug Fragments (1) 29
#engageug Fragments (2) 30 fragment code use it multiple times
#engageug Attachments • Forget the UploadedFile, learn MultipartFile • MultipartFile has lots of similarities with UploadedFile, but easier to use. Less code to achieve the same 31
#engageug Security 32
#engageug Spring Security • Framework for Authentication and Authorisation • Prevention of clickjacking, CORS, cross site request forgery • Integrates with Spring Boot and Thymeleaf • Customisable • Support for Basic Authentication, SAML2, oAuth and more. 33
#engageug Configuration 34 CORS prevention
#engageug Spring security in Thymeleaf 35 add to pom.xml add namespace
#engageug New possibilities 36
#engageug 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) 37
#engageug Lombok 38 add to pom.xml add @Data using the build in logging
#engageug Swagger • Part of Open API Specification, since v3 • Documentation of API’s • Playground for testing • Add annotation to generate the documentation dynamically 39
#engageug Swagger 40 add to pom.xml add a configuration add annotation to endpoint
#engageug 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 41
#engageug Jenkins file 42
#engageug Questions 43
#engageug 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/ 44
#engageug Resources • Swagger • http://swagger.io • Thymeleaf documentation • http://www.thymeleaf.org/ • Maven • https://maven.apache.org/ • Gradle • https://gradle.org/ • Spring Forward Starter • https://bitbucket.org/flinden68/spring-forward-starter 45
#engageug Reach out to me • @flinden68 • http://www.elstarit.nl • flinden68@elstarit.nl • https://nl.linkedin.com/in/flinden68 46

Spring forward: an introduction to Spring boot and Thymeleaf