Java Magazine, Jan/Feb 2016
ORACLE COM JAVAMAGAZINE JANUARY FEBRUARY 2016 16 web apps Actuator Spring Boots web services component Remote Shell H2 the database and Thymeleaf a templating engine See Figure 1 Then click Generate Project to download a zip file that you can open in your favorite IDE When you open the project youll see that theres a simple public static void main method and an empty unit test Youll also find two empty directories static and templates in the src main resources directory Templates that are processed on the server side such as FreeMarker Velocity and Thymeleaf live in the templates directory Assets that will be sent to the client directly such as JavaScript images CSS and so forth live in the static directory In Figure 2 Ive shown the directory complete with a sample Thymeleaf template reservations html and a simple hi html file to be sent to an HTTP client unprocessed Open the Maven build file pom xml Youll see that it contains dependencies that correspond to checkboxes selected in Spring Initializr The various starter dependencies are opinionated dependencies they dont contain code instead they just bring in other dependencies For example org springframework boot spring boot starter datajpa brings in everything youre likely to need to get started with JPA the latest and greatest JPA 2 specification types the latest Hibernate implementation Springs support JPA ORM JDBC and so on You dont have to worry about managing version ranges or lining up dependencies across common libraries Maven has the ability to import or inherit build configuration from other build artifacts Spring leverages this feature and exposes a useful parent build that defines version ranges and other needed items such as dependencies like the Servlet API Hibernate and so forth There are two benefits to this approach you can omit version declarations for the dependencies that are predefined for you and you can update to the latest version of Spring Boot when a new version rolls around by simply overriding the version of the parent build that youre using All the associated dependencies will be upgraded in lockstep automatically The Data Speaks for Itself Lets create a simple JPA entity Reservation java that we can manipulate in our application package com example import javax persistence Entity import javax persistence GeneratedValue import javax persistence Id Figure 2 The populated project directory
You must have JavaScript enabled to view digital editions.