Skip to main content

Spring Tools Suite

Introduction

Spring Tools Suite (STS) is a specialized Integrated Development Environment (IDE) built on top of Eclipse that provides a comprehensive development environment for building Spring applications. It's designed to make development with the Spring Framework faster and easier with features specifically tailored for Spring projects.

Spring Tools Suite offers intelligent code completion, quick navigation, validation, and refactoring tools that understand Spring's application context and bean definitions. Whether you're a beginner just starting with Spring or an experienced developer working on complex Spring-based applications, STS can significantly improve your productivity.

What is Spring Tools Suite?

Spring Tools Suite is more than just an IDE; it's a complete toolset for developing Spring applications. It includes:

  • Spring-aware tools - Built-in knowledge of Spring projects and conventions
  • Code templates - Quick scaffolding for Spring components
  • Spring Boot support - Specialized tooling for Spring Boot applications
  • Visual editors - For Spring configuration files
  • Integration with Spring Cloud - Tools for microservices development

Getting Started with Spring Tools Suite

Installation

There are two primary ways to get Spring Tools:

  1. Standalone STS Distribution: A complete IDE package
  2. Extension Pack for existing IDEs: Plugins for Eclipse, Visual Studio Code, or Theia

Downloading the Standalone STS

  1. Go to spring.io/tools
  2. Download the appropriate version for your operating system (Windows, macOS, or Linux)
  3. Extract the downloaded archive
  4. Run the STS executable

Installing as Extensions

For Visual Studio Code:

  1. Open VS Code
  2. Go to Extensions (Ctrl+Shift+X)
  3. Search for "Spring Boot Tools"
  4. Install the extension

For Eclipse:

  1. Open Eclipse
  2. Go to Help > Eclipse Marketplace
  3. Search for "Spring Tools"
  4. Install the Spring Tools 4 package

Creating Your First Spring Boot Project in STS

Let's create a simple Spring Boot application that displays "Hello, Spring!" on a web page:

  1. Open Spring Tools Suite

  2. Click on File > New > Spring Starter Project

  3. Fill in the project details:

    • Name: hello-spring
    • Type: Maven
    • Packaging: Jar
    • Java Version: 17 (or your preferred version)
    • Group: com.example
    • Artifact: hello-spring
    • Package: com.example.hellospring
  4. Click Next, then select the following dependencies:

    • Spring Web
    • Spring Boot DevTools
  5. Click Finish to create the project

STS will generate a Spring Boot project with all the necessary dependencies and configurations.

Key Features of Spring Tools Suite

Spring Boot Dashboard

The Spring Boot Dashboard is one of the most useful features in STS. It provides a centralized view to manage all your Spring Boot applications.

To access it:

  1. Open the Spring Boot Dashboard view (Window > Show View > Other > Spring > Boot Dashboard)
  2. From here, you can:
    • Start/stop applications
    • Open applications in a browser
    • Restart applications
    • View application status

Live Application Information and Metrics

When running a Spring Boot application, STS provides real-time information about:

  • Request mappings
  • Bean definitions
  • Auto-configuration reports
  • Application health metrics

Built-in Support for Spring Initializr

STS integrates Spring Initializr directly into the IDE, allowing you to quickly bootstrap Spring projects with the dependencies you need.

Code Assistance and Navigation

STS provides enhanced code assistance for Spring-specific code:

  • Smart completions - Context-aware suggestions for Spring annotations and properties
  • Quick navigation - Jump directly to bean definitions or autowired dependencies
  • Validation - Highlights potential issues in Spring configuration

Practical Example: Building a REST API with STS

Let's build a simple REST API for a book catalog:

  1. Create a new Spring Boot project as described earlier, with dependencies:

    • Spring Web
    • Spring Data JPA
    • H2 Database
  2. Create a Book entity class:

java
package com.example.bookcatalog.model;

import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;

@Entity
public class Book {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String title;
private String author;
private String isbn;

// Constructors
public Book() {}

public Book(String title, String author, String isbn) {
this.title = title;
this.author = author;
this.isbn = isbn;
}

// Getters and Setters
public Long getId() { return id; }
public void setId(Long id) { this.id = id; }

public String getTitle() { return title; }
public void setTitle(String title) { this.title = title; }

public String getAuthor() { return author; }
public void setAuthor(String author) { this.author = author; }

public String getIsbn() { return isbn; }
public void setIsbn(String isbn) { this.isbn = isbn; }
}
  1. Create a repository interface:
java
package com.example.bookcatalog.repository;

import com.example.bookcatalog.model.Book;
import org.springframework.data.jpa.repository.JpaRepository;

public interface BookRepository extends JpaRepository<Book, Long> {
}
  1. Create a controller:
java
package com.example.bookcatalog.controller;

import com.example.bookcatalog.model.Book;
import com.example.bookcatalog.repository.BookRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Optional;

@RestController
@RequestMapping("/api/books")
public class BookController {

@Autowired
private BookRepository bookRepository;

// Get all books
@GetMapping
public List<Book> getAllBooks() {
return bookRepository.findAll();
}

// Create a new book
@PostMapping
public Book createBook(@RequestBody Book book) {
return bookRepository.save(book);
}

// Get a book by ID
@GetMapping("/{id}")
public Book getBookById(@PathVariable Long id) {
return bookRepository.findById(id)
.orElseThrow(() -> new RuntimeException("Book not found"));
}

// Update a book
@PutMapping("/{id}")
public Book updateBook(@PathVariable Long id, @RequestBody Book bookDetails) {
Book book = bookRepository.findById(id)
.orElseThrow(() -> new RuntimeException("Book not found"));

book.setTitle(bookDetails.getTitle());
book.setAuthor(bookDetails.getAuthor());
book.setIsbn(bookDetails.getIsbn());

return bookRepository.save(book);
}

// Delete a book
@DeleteMapping("/{id}")
public void deleteBook(@PathVariable Long id) {
bookRepository.deleteById(id);
}
}
  1. Configure the application properties in src/main/resources/application.properties:
properties
# H2 Database Configuration
spring.datasource.url=jdbc:h2:mem:bookcatalog
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.username=sa
spring.datasource.password=

# Enable H2 Console
spring.h2.console.enabled=true
spring.h2.console.path=/h2-console

# JPA Configuration
spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=update
  1. Run the application:

    • Right-click the project in STS
    • Select Run As > Spring Boot App
    • The application will start and be accessible at http://localhost:8080
  2. Test your REST API:

Example curl commands:

bash
# Create a book
curl -X POST http://localhost:8080/api/books -H "Content-Type: application/json" -d '{"title":"Spring in Action", "author":"Craig Walls", "isbn":"9781617294945"}'

# Get all books
curl http://localhost:8080/api/books

# Get a specific book
curl http://localhost:8080/api/books/1

# Update a book
curl -X PUT http://localhost:8080/api/books/1 -H "Content-Type: application/json" -d '{"title":"Spring in Action, 6th Edition", "author":"Craig Walls", "isbn":"9781617294945"}'

# Delete a book
curl -X DELETE http://localhost:8080/api/books/1

Spring Tools Suite Productivity Tips

Keyboard Shortcuts

Learning keyboard shortcuts can significantly speed up your development:

ActionShortcut (Windows/Linux)Shortcut (macOS)
Open Spring Boot DashboardAlt+Shift+B⌥⇧B
Go to BeanCtrl+Alt+G⌥⌘G
Open TypeCtrl+Shift+T⇧⌘T
Quick FixCtrl+1⌘1
Run as Spring Boot AppAlt+Shift+X, B⌥⇧X, B

Customizing STS

You can customize STS to match your preferences:

  1. Go to Window > Preferences (Eclipse > Preferences on macOS)
  2. Explore sections like:
    • Java > Code Style
    • Spring > Boot > Initializr
    • General > Appearance

Spring Boot DevTools Integration

When working with Spring Boot applications, STS integrates seamlessly with Spring Boot DevTools to provide:

  • Automatic restarts - When code changes are detected
  • LiveReload support - Browser refresh when static resources change
  • Property defaults - Sensible development-time properties

Debugging Spring Applications in STS

STS provides powerful debugging capabilities specifically designed for Spring applications:

  1. Set breakpoints by double-clicking on the line number margin
  2. Right-click the project and select Debug As > Spring Boot App
  3. When execution stops at a breakpoint, you can:
    • Inspect variables
    • Step through code execution
    • Evaluate expressions
    • View the Spring application context

For Spring applications, STS provides special views for:

  • Bean definitions
  • Request mappings
  • HTTP request/response details

Common Issues and Solutions

STS Performance Issues

If STS feels slow:

  1. Increase heap memory by editing the SpringToolSuite4.ini file and adjusting the -Xmx value
  2. Disable unnecessary validation or background tasks in Preferences
  3. Consider closing projects you're not actively working on

Spring Boot Application Won't Start

If your Spring Boot application fails to start:

  1. Check the Console view for detailed error messages
  2. Verify port availability (default is 8080)
  3. Review application.properties for configuration errors
  4. Check dependencies in pom.xml or build.gradle

IDE Shows Errors but Code Compiles

Sometimes STS may show red error markers even though the code compiles:

  1. Try Project > Clean...
  2. Right-click the project and select Maven > Update Project...
  3. Check that you have the correct Java compiler level set in Project Properties

Summary

Spring Tools Suite is a powerful IDE specifically designed for developing Spring applications. It provides specialized tools that understand Spring concepts and configurations, which can significantly improve your productivity when working with the Spring ecosystem.

Key takeaways:

  1. STS provides Spring-aware tooling to accelerate development
  2. The Spring Boot Dashboard makes managing applications easy
  3. Code assistance features understand Spring concepts
  4. Integration with Spring Initializr helps jumpstart new projects
  5. Debugging tools provide insight into Spring's internals

Whether you're building a simple web application or a complex microservice architecture, Spring Tools Suite offers features that make development more efficient and enjoyable.

Additional Resources

Exercises

  1. Hello World Application: Create a simple Spring Boot web application that displays "Hello World" on the homepage using STS.

  2. REST API Practice: Extend the book catalog example by adding search functionality, such as finding books by author or title.

  3. Database Integration: Create a Spring Boot application that connects to a MySQL or PostgreSQL database instead of H2, configuring the connection in STS.

  4. Spring Security: Add authentication to a Spring Boot application using Spring Security and configure it through STS.

  5. Spring Tools Exploration: Explore the different views in STS, such as the Beans view, Boot Dashboard, and Request Mappings view, and document how they can help in development.



If you spot any mistakes on this website, please let me know at [email protected]. I’d greatly appreciate your feedback! :)