· Jose Antonio López · 8 min read
Key Dependencies in Spring Boot for Development
What do you need for basic development in Spring Boot? What dependencies can you use for a technical test?

Introduction
Explanation of the essential dependencies for developing with Spring Boot 3.3.5 excluding testing dependencies. I have also included some of my preferred libraries that help me in my daily work.
All dependencies are in Maven format, as I consider it easier to understand for beginners and I have more experience with Maven than with Gradle.
Spring Web
Dependency
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>Purpose
For any web application or REST API, this is the base. When the application starts, a Tomcat web server insatnce is launched. It allows listening and responding to HTTP requests. It translates what arrives in the HTTP request and passes it to the Java program that knows how to handle it.
Explanation
In the past, configuring a Tomcat server from scratch could take a lot of time. With Spring Web, everything comes by default so you can just click “play” in the IDE. It will allow you to use:
- @RestController to handle HTTP requests.
- @RequestMapping to map an HTTP request to a method.
- @GetMapping to map an HTTP GET request to a method.
- @RequestBody to read the body of an HTTP request.
How does the information flow work?
@RestController is responsible for handling the HTTP request that has arrived through Tomcat. At least, it knows of a specific @RequestMapping. Everything that arrives in its @RequestMapping will be delegated to a method that knows what to do with the request.
If a GET request arrives at /customers/600d3f72-d96e-4e4f-ac35-1b814b357ddf, the getCustomer(UUID id) method will know what to do with the request.
Below is an example of how clean code would look:
import static com.test.crm.config.ApiConfig.API_BASE_PATH;
@RestController
@RequestMapping(API_BASE_PATH + "/customers")
public class CustomerController {
private final CustomerService customerService;
public CustomerController(CustomerService customerService) {
this.customerService = customerService;
}
@GetMapping("/{id}")
public CustomerDTO getCustomer(@PathVariable UUID id) {
return customerService.getCustomer(id);
}
}For a complete explanation of Spring Boot Rest Controller with CRUD, visit Spring Boot Rest Controller with CRUD.
Spring Security
Dependency
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>Purpose
Provides authentication and authorization for applications. It is the dependency that will allow you to manage access to the application.
Explanation
Due to the complicated nature of security, it is the dependency that, in my opinion, is the hardest to understand. Start with basic authentication. If you have a User class, implement the UserDetails interface.
To enable security, create a class and paste the following code with debug. The debug will allow you to know what is happening. In production code, you should remove the debug.
@Configuration
@EnableWebSecurity(debug = true)
public class SecurityConfig {
}Finally, follow the official Spring Boot guide to configure your application’s security with Basic Authentication.
Spring Data JPA
Dependency
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>Purpose
Facilitates integration with relational databases using JPA. Simplifies database operations with repositories and queries. JPA allows developers to work with objects instead of working with rows, columns, and tables separately.
Explanation
JPA is a specification or contract. Hibernate is a provider that complies with what JPA says must be complied with. By using this dependency, it comes configured by default with Hibernate.
To activate it, you must create a class with at least the following code:
@Configuration
@EnableJpaRepositories
public class JpaConfig {
}JPA allows you to use annotations to map your classes to database tables. For example, if you have a Customer class, you can map it to a table as follows:
@Entity
@Table(name = "customers")
public class Customer {
@Id
@UuidGenerator(style = UuidGenerator.Style.AUTO)
private UUID id;
@Column(nullable = false)
private String name;
@Column(nullable = false)
private String surname;
@Column()
private String image;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(
name = "created_by",
nullable = false,
updatable = false
)
@CreatedBy
private User createdBy;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(
name = "last_updated_by",
nullable = false
)
@LastModifiedBy
private User lastUpdatedBy;
}PostgreSQL
Dependency
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>Purpose
Provides the JDBC driver to connect to PostgreSQL databases. JDBC is a component designed so that any Java application can talk to databases. There are JDBC drivers for most databases, and there are 4 types of JDBC drivers. The most used is type 4, also called pure JDBC.
Explanation
To configure the database connection, you can add the following lines to your application.yaml file:
spring:
datasource:
url: jdbc:postgresql://localhost:5432/testdb
username: myuser
password: mypassword
jpa:
hibernate:
ddl-auto: create-drop
show-sql: true
defer-datasource-initialization: true
sql:
init:
mode: alwaysIf you want to visualize the database data, I recommend installing the dbeaver program in its desktop version. It is a free and open-source program that allows you to visualize the database data.
You can download DBeaver from its official page.
H2
Dependency:
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>Purpose
Provides an in-memory database for testing and rapid development. H2 is a lightweight and fast database that runs in memory, meaning it requires no additional configuration or installation. It is ideal for proof-of-concept or rapid development such as simple technical tests.
Additionally, H2 offers a web console that facilitates data visualization and manipulation during development. It saves you from having to install a database on your local machine.
Explanation
To configure the database connection, you can add the following lines to your application.yaml file:
spring:
datasource:
url: jdbc:h2:mem:testdb
username: sa
password: password
h2:
console:
enabled: true
jpa:
hibernate:
ddl-auto: update
show-sql: trueWhat you gain with H2 is avoiding Docker concepts or installing a database. When you are learning or doing quick proof-of-concept tests, it is great.
If you have more knowledge, opt to use PostgreSQL instead of H2 for more realistic development environments.
Validation
Dependency
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>Purpose
Provides support for data validation in Spring Boot applications. Ensuring that input data is valid is essential because it allows controlled filtering of the data that the backend expects. No one wants a String when expecting an Integer or a Boolean.
Explanation
If you go to the Spring Boot validation guide, you will see that the Spring team does not give you much information. They talk about JSR-303 implementation.
The Spring team wants to tell you that to use validations, you need someone to implement JSR-303. Hibernate implements that specification, so we are in luck because it comes by default in Spring Boot.
To see what validations exist, check the Hibernate Validator documentation.
To use validations, simply add the Hibernate Validator annotations to your classes. For example, if you have a class to create a customer, you can add the following annotations:
public record CreateUserDTO(
@NotBlank
@Size(min = 3)
@Pattern(regexp = "^[^0-9]*$") //Only letters accepted
String username,
@Email
String email
) {
}Containers with Docker
Dependency
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-docker-compose</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>Purpose
Facilitates the creation and deployment of applications in Docker containers. A file called compose.yaml is installed at the root.
The compose.yaml file contains the basic configuration to launch a Docker container with a database. The magic comes from Spring’s autoconfiguration that detects the compose.yaml, launches the container, launches the application, and connects it to the database.
You can find a complete guide to setting up a compose.yaml file in Setting up a Spring Boot Project for Development.
Explanation
You may also find that a Dockerfile is used at the root as follows:
Dockerfile:
FROM openjdk:17-jdk-slim
VOLUME /tmp
COPY target/*.jar example.jar
ENTRYPOINT ["java","-jar","/example.jar"]Personally, nowadays I prefer to use the compose.yaml with environment variables and define the variables in a .env file.
DevTools
Dependency
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
</dependency>Purpose
Enhances the development experience by providing features such as automatic reload and development configurations.
Explanation
DevTools caches and monitors files. If a file is modified and is in the project’s classpath, the application restarts automatically.
In my daily work, I use it frequently without even realizing it. The reason is that for Java development, I use IntelliJ IDEA. It works very well for restarting the application when developing or debugging. Often, I don’t even remember that DevTools are activated.
For a detailed guide on configuring DevTools in Spring Boot, visit this link.
Springdoc OpenAPI
Dependency:
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
</dependency>Purpose
Facilitates the generation of OpenAPI documentation. OpenAPI is an industry specification for describing RESTful APIs that allows developers to understand each other. If you have a RESTful API, it is essential to have clear and precise documentation.
Explanation
It is very useful for generating and maintaining API documentation and provides a graphical interface based on Swagger UI that allows developers and QA to explore and test API endpoints without needing Postman or Insomnia.
If you are at a very high technical and functional knowledge level, the first step is to design the API. A good step is to use OpenAPI to design the API and then implement it. The approach is not to touch the code until the API has an initial basic design.
Apache Commons Lang
Dependency:
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>Purpose
This library is not native to Spring Boot. It provides additional utilities for string manipulation.
Explanation
The utility I use the most is StringUtils.isBlank(). It is a safe way to check if a string is null or empty.
The most useful feature of the library is the ability to override the hashCode and equals methods. In a job I had, we used it as follows, and I always use it this way when I don’t use Lombok:
@Override
public boolean equals(Object object) {
return EqualsBuilder.reflectionEquals(this, object);
}
@Override
public int hashCode() {
return HashCodeBuilder.reflectionHashCode(this);
}Lastly, the library has many utilities that use Reflection in between. Do not overuse it, and if necessary, consult the official documentation or with your work team.
Next Steps
With these dependencies, you can now start building your application. If you want to see how to implement them in a real case, I recommend following the guide to create a REST CRUD API with Spring Boot. You can also learn advanced testing techniques such as loading JSON files for unit tests.
t-rest-controller-crud).
- Java
- Spring Boot