Simple JWT Authentication in Spring Boot
JWT (JSON Web Token) is an open standard (RFC 7519) used for the secure exchange of information between parties in JSON format. It is most commonly used for authentication and authorization of users in web and mobile applications.
Why is JWT so popular?
- 🔑 Stateless – the server doesn’t need to store sessions, the token itself is enough.
- ⚡ Efficient – the token is sent in the HTTP header and verified quickly.
- 🌍 Universal – works across different environments (web, mobile, microservices).
- 🔒 Secure – the digital signature guarantees that the token has not been tampered with.
In practice, it works like this: a user logs in → receives a JWT → uses it in subsequent requests to the API. Thanks to this, the application remains scalable and easy to maintain.

Example Implementation
Below you’ll find an example of a simple JWT mechanism with Spring Boot 3 to help you get a secure JWT-protected API up and running.
What’s included in the implementation:
- Basic Auth + JWT: Log in with credentials, receive a JWT token, and use it for subsequent requests.
- PostgreSQL: User data is stored in a real database.
- Swagger UI: Explore and test all endpoints at
http://localhost:8088/swagger-ui/index.html.
Setup in 4 Steps
- Clone the repository
git clone https://github.com/marcinzygmunt-pl/spring-boot-jwt-basic.git
cd spring-boot-jwt-basic
- Configure PostgreSQL
Edit theapplication.ymlfile with your database credentials. - Run the application
./mvnw spring-boot:run
- Test endpoints in Swagger UI
And that’s it! You now have a fully functional JWT-secured API.
spring-boot-jwt-basic was designed as a practical starter project. Within minutes, you can launch a working JWT authentication flow – without unnecessary complexity.
See also:
- JWT with refresh
- JWT with refresh in CACHE
- JWT with refresh in HAZELCAST