This article shows how to quickly build a web application using the Spring Tools Suite.

For this tutorial, I use Spring Tools 4 for Eclipse, where I initialize projects using Eclipse wizards.

Spring Boot Web Application

Spring has a lot of components, and SpringBoot is a convention over configuration approach to run an application with default modules loaded.

  • main() launch the Spring Boot application
  • @SpringBootApplication wraps common configuration
  • SpringApplication.run() start Spring, instantiate the Context and set up controllers.
  • start and configure an embedded tomcat to serve content.

Use case Banking

As a use case, I am re-using the Banking Model, presented in this article, and in one of my talks at EclipseCon Europe: Rapid Prototyping of Eclipse RCP Applications.

Initialize Spring Boot Application

Press Ctrl + N (Cmd+M on mac) to open the New .. wizard, and select Spring Starter Project.

Provide com.asciiware.spring.banking.app as application Name, Group, and Package, as you see in the image below, then click Next.

Note: by keeping defaults, we use Maven with Java 8 to build an application as a Jar.

Then, choose the dependencies listed below, and click Finish.

  • Spring Web Starter: to build web/REST application, also embeds Tomcat
  • Thymeleaf: add server-side templating engine
  • Spring Data JPA: DB persistence with Hibernate / JPA
  • H2 Database: in memory DB
  • Spring Boot Dev Tools: fast reload/restart, and enhanced configurations.

Note: this page is just a frontend for start.spring.io, where we can choose application dependencies.

Look in the package explorer and find the Application class implementing your spring boot application, annotated as @SpringBootApplication

Add a Controller class, to handle requests to the root directory of your web application. The class con

In the following wizard page keep

When the wizard is down we have a Spring application with all the dependencies needed to run the Application.

Dependency Injection

References


0 Comments

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *