Spring Tool Suite & Groovy/Grails Tool Suite Starting with 3.0.0, we are building two separate distributions of our tool suite for you: The Spring Tool Suite provides all the necessary bits and pieces for working with Spring projects, including the Spring framework IDE support, tc Server integration, and support for Spring Roo. Feeling adventurous? Download the latest snapshot release. Credits Copyright © 2009-2020 The Project Lombok Authors, licensed under the MIT license. Copyright.
This tutorial will show you how to build a simple web app using Spring Framework and STS (Spring Tool Suite). It’s a beginner guide and it will help you if you are new to Spring or STS.
NOTE: This tutorial requires Spring STS to be installed and configured with Eclipse IDE. If you haven’t done this step yet please read Install Spring STS in Eclipse first.
What is Spring Boot
This tutorial uses Spring Boot to create a simple web-app with running on embedded Tomcat server.
Spring Boot is Spring’s solution for creating stand-alone applications that are easy to build and run. It uses preconfigured Spring platform and third-party libraries so you can get started within minutes. Most Spring Boot applications need very little Spring configuration. This particular example does not need any configuration at all.
Features of Spring Boot:
- Create stand-alone Spring applications
- Embed Tomcat or Jetty directly (no need to deploy WAR files)
- Provide POM file to simplify your Maven configuration
- Automatically configure Spring whenever possible
- Provide production-ready features such as metrics, health checks and externalized configuration
- Absolutely no code generation and no requirement for XML configuration
Create New Spring Starter Project
Spring Tool Suite Download For Windows 10
1. Start Eclipse and go to File -> New -> Other… or press Ctrl+N on your keyboard
In the search field type “spring”. This will list several Spring options. The one we need for this tutorial is “Spring Starter Project”. Select it and confirm with “Next” button
2. Use the setting shown in the screenshot below.
Choose a name for your project. Select Maven as build tool, JAR packaging and your Java version.
Under Package type the package name. Artifact is the name of the JAR file you are going to build. For example if you use springexample as artifact the final JAR file will be called springexample.jar
Spring starter project settings
3. In “New Spring Starter Project Dependencies” window select Web.
If you can’t find it in the list, use the search field and type into it “web”
Confirm with “Finish” button. STS will create the project for you and download all needed dependencies.
4. Once the project is created you will see one main Java class called
SpringBootExampleApplication.java, one Java class for testing purposes, empty properties file, a Maven POM file and 2 files to execute the application from command line. In the screenshot below you will see on the left the project structure and the content of the main class on the right.
Spring Boot web-project structure
Run Your Spring Boot Application
Right-click your project, go to “Run As” and select “Spring Boot App”
This will bootstrap the embedded Tomcat server, deploy your app and map the URLs. In Eclipse console you will see an output similar to this one:
Once the application is started, open your browser and navigate to http://localhost:8080
You will see a page labeled “Whitelabel Error Page”. This is totally fine. Don’t worry. It indicates that the server is started, but there is no mapping available for URL “/”. We will fix this in the next step.
Spring whitelabel error page
Create a Request Mapping
Now, to be able to see some “meaningful” content under http://localhost:8080 we need to change the code of
SpringBootExampleApplication.java a bid. First annotate the class with
@Controller annotation. Second create a request mapping to URL “/” – this will map the
home() method to this URL. In other words when the browser makes a GET request to http://localhost:8080 it will be served by this method. Finally to be able to return a response to the browser you need to annotate the
home() method with
@ResponseBody. You will find all the changes below:
Relaunch the Spring Boot App
Before you can see the changes you just did in the previous step you need to redeploy you changed app. To achieve this use the “Spring relaunch button” shown on the screenshot below
Now go to your browser and refresh the page. You should see the string our
home() method returns on the screen
Complete source code of the project can be found in our GitHub repo under: https://github.com/JavaTutorialNetwork/Tutorials/tree/master/SpringBootExample
Spring Tools Suite
Spring Tool Suite 4 Download
- Install Spring STS in Eclipse
This guide shows you how to install Spring Tool Suite in Eclipse STS stands for Spring Tool Suite. It provides ready-to-use environment to implement, run,…
- Java Servlet Example
In this tutorial I will show you how to create Servlets and deploy them in Apache Tomcat 8 What are Servlets? Servlets are the building…
- Java JSP Example
This example demonstrates how to create a simple JSP page In my previous tutorials I have shown you how to use Servlets to handle requests,…