Java 21 + Spring Boot 3 codebase containing real-world examples (CRUD, authentication, advanced patterns, etc.) that adheres to the RealWorld specification and API.
This codebase demonstrates a fully-fledged fullstack application built with Java 21 + Spring Boot 3, including CRUD operations, authentication, routing, pagination, and more.
If you want to see the API documentation related to this, please refer to https://1chz.github.io/realworld-java21-springboot3
For more information on how this works with other frontend/backends, visit the RealWorld repository.
While implementing this application, the following considerations were made:
- Error Handling: The application handles errors gracefully and logs them appropriately.
- Scalability: Designed to scale for large volumes of data.
- Security: Protects against common attacks and implements robust authentication and authorization.
- Code Quality: Clean, maintainable code that follows best practices.
- Performance: Optimized for frequently used operations through database indexing, query optimization, and caching.
- OAuth 2.0 Resource Server: Used for simpler JWT implementation compared to manual implementations.
- Spring Framework: Tightly coupled with Spring due to its robustness and backward compatibility within the Java ecosystem.
- Database Abstraction: Implemented with JPA to simplify database changes.
- H2 Database: Used in MySQL mode to provide similar functionality to MySQL.
- Input Validation: Not included but can easily be implemented using JSR-303 (Bean Validation 2.0).
- Slug and Title Uniqueness: Ensured uniqueness according to API specifications.
- Dependencies: Structured to converge on the domain package for better organization.
The RealWorld project aims to create mini-blog applications with identical specifications using various technology stacks, allowing for easy comparison.
This application provides the following key features:
- User authentication via JWT (login/signup pages, logout button on settings page)
- Create, read, and update users (sign up & settings page; deleting users is not required)
- CRUD operations for articles (offset-based pagination, filtering by facets, sorting)
- Create, read, and delete comments on articles (updating comments is not required)
- Favorite articles
- Follow other users
The project is implemented using Java 21 and Spring Boot 3, leveraging technologies such as Spring MVC, Spring Data JPA, and Spring Security. It uses H2 DB (in-memory, MySQL mode) as the database and JUnit 5 for testing.
To run the project, ensure that JDK (or JRE) 21 is installed. Then, execute the following command in the project root directory:
./gradlew realworld:bootRun
Access the application at http://localhost:8080 in your browser.
The project is organized into library and server modules:
-
Library Modules (located in the
module
directory):core
: Contains core logic, domain models, service interfaces, and exception handling.persistence
: Contains persistence layer logic, repositories, and entities.
-
Server Modules (located in the
server
directory):api
: Contains the API layer logic, controllers, DTOs, and exception handling.
All modules depend on the core module, following the Dependency Inversion Principle (DIP).
- Controller: Handles HTTP requests, invokes business logic, and generates responses.
- Service: Implements business logic and interacts with the database via repositories.
- Repository: Interfaces for database operations, implemented using Spring Data JPA.
Note: Data types were carefully considered, but column sizes were not a primary focus.
Many developers using JPA tend to use Long
as the ID type. However, consider whether your table will ever require storing (2^{63}) records.
Note: Ensure JDK 21 is installed.
Note: If you encounter a permission denied error when running Gradle tasks, run
chmod +x gradlew
to grant execution permission.
API documentation is available at https://1chz.github.io/realworld-java21-springboot3, generated using ReDoc in HTML format.
You can also import the api-docs/openapi.yaml file into Postman or Swagger UI to test the API.
./gradlew realworld:bootRun
Note: The code style task runs automatically during the build. If the code style does not match, the build will fail.
./gradlew spotlessApply
./gradlew test
./gradlew build
- Start the application (important)
- Run E2E tests