DEV Community

William
William

Posted on

Create project using Spring Boot 3

To start the series of posts about How to build REST API with Spring Boot 3, we need to create the initial project files and some configurations.
This series will explore the steps to implement the entity, service, and control layers about RESP API.

If you don't kwon what is REST API, I recommend you read this post from Amazon.

Create a project

To make our lives easier, I will use https://start.spring.io.
Choose project by maven with the language JAVA 21, the version of spring boot can be 3.2.1.
On the right of the screen, add this dependencies:

  • Spring Web
  • Spring Data JPA
  • Spring Boot DevTools

In Project Metadata you can put the name of your project like this:
Group: com.spring
Artifact: SprignRest
Name: SprignRest
Description: Api Rest with Spring Boot
Package name: com.spring

Look to the picture to see the final configuration
start.spring.io
After click em GENERATE, it'll download the project, unzip the file to the folder that you want.
Open this file in your favorite IDE, I will use IntelliJ, and go to the file pom.xml.
Add another dependency h2database inside dependencies tags and reload the project to import the new dependency.

<dependency>
    <groupId>com.h2database</groupId>
    <artifactId>h2</artifactId>
    <scope>runtime</scope>
</dependency>
Enter fullscreen mode Exit fullscreen mode

pom.xml

Firts configuration

In the application.properties we need to configure the H2 database

spring.jpa.hibernate.ddl-auto=update

spring.datasource.url=jdbc:h2:mem:restdb
spring.datasource.username=sa
spring.datasource.password=

spring.h2.console.enabled=true
spring.h2.console.path=/h2-console
Enter fullscreen mode Exit fullscreen mode

How our database will be in memory, we need that the spring boot be responsible for create the tables, columns...
The first line do it.

The second block is to configure access settings for our database
And the final is to enable the console of H2 database.

Run the project

Go to the SprignRestApplication class and click to start the application.
See the logs to guarantee that application is working in port default 8080 and H2 database too.

logs

Open http://localhost:8080/h2-console in your browser.
This is the endpoint about your database application, put the url,username and password equals to in application.properties to be able to see informations.
In this point the database will be null, but in the next post we'll configure the tables and records.

h2login

Conclusion

In this first post, we configure the initial dependencies and our database so that our project is ready to receive implementations of a REST API.

Next Step

In the next step we will create an Entity class and some records for our application.

Top comments (0)