A full-stack ready Spring Boot REST API for a blogging platform with JWT authentication, PostgreSQL database, Spring Data JPA, and Swagger API documentation powered by springdoc-openapi. This project is containerized with Docker and deployable to Render.com.
-
User Authentication & Authorization
- Registration and Login endpoints using JWT token-based authentication.
- Public routes for login, register, and fetching all blogs.
- All other routes are secured using Spring Security.
-
Blog Management
- Create, Read, Update, Delete (CRUD) operations for blog posts.
- Each post is associated with a registered user.
-
CORS Configuration
- Configured to work seamlessly with a frontend React app.
- Custom
SecurityFilterChainensures correct CORS and endpoint access rules.
-
API Documentation
- Interactive API documentation using SpringDoc OpenAPI.
- Available at
/swagger-ui/index.html.
-
Database
- PostgreSQL database integration via Spring Data JPA.
- Configured with environment variables for flexible deployment.
-
Testing
- Unit tests for both
BlogServiceandBlogControllerusing JUnit 5, Mockito, AssertJ, and MockMvc.
- Unit tests for both
| Layer | Technologies |
|---|---|
| Backend | Java 17, Spring Boot |
| Security | Spring Security, JWT |
| Persistence | Spring Data JPA, PostgreSQL |
| Documentation | SpringDoc OpenAPI (Swagger) |
| Build Tool | Maven |
| Testing | JUnit 5, Mockito, AssertJ, MockMvc |
| Containerization | Docker |
| Deployment | Render.com |
- Java 17 or higher
- Maven 3.9+
- PostgreSQL installed locally
- Docker Desktop (optional, for containerized run)
git clone https://github.com/shuvojoseph/BlogPostSpringBoot.git cd BlogPostSpringBootUpdate src/main/resources/application.properties with your PostgreSQL credentials:
spring.datasource.url=jdbc:postgresql://localhost:5432/BlogDB spring.datasource.username=postgres spring.datasource.password=root spring.jpa.hibernate.ddl-auto=update spring.jpa.show-sql=trueRun PostgreSQL locally, then start the app:
./mvnw spring-boot:runVisit Swagger UI at: 👉 http://localhost:8080/swagger-ui/index.html
Spring Boot automatically detects test classes under src/test.
Run all tests:
./mvnw testRun only service tests:
./mvnw -Dtest=BlogServiceTest testRun only controller tests:
./mvnw -Dtest=BlogControllerTest testA two-stage Docker build is used — first for compilation, then for runtime:
# ---- build stage ---- FROM maven:3.9.4-eclipse-temurin-17 as build WORKDIR /workspace COPY pom.xml mvnw ./ COPY .mvn .mvn RUN ./mvnw -B -f pom.xml dependency:go-offline COPY src ./src RUN ./mvnw -B -f pom.xml package -DskipTests # ---- runtime stage ---- FROM eclipse-temurin:17-jre-jammy WORKDIR /app ARG JAR_FILE=target/*.jar COPY --from=build /workspace/${JAR_FILE} app.jar EXPOSE 8080 ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app/app.jar"]docker build -t blogpost:local . docker run -p 8080:8080 \ -e PORT=8080 \ -e SPRING_DATASOURCE_URL="jdbc:postgresql://host.docker.internal:5432/BlogDB" \ -e SPRING_DATASOURCE_USERNAME=postgres \ -e SPRING_DATASOURCE_PASSWORD=root \ -e APP_JWT_SECRET="Q1kzRVMycnlIN2ZzR3dpamJaa2RwcU41aGlDUUhtZXc=" \ blogpost:localAccess the API at: 👉 http://localhost:8080/swagger-ui/index.html
- Push this project to your GitHub account.
- Log in to Render and click “New Web Service”.
- Select this GitHub repository.
- Add the following Environment Variables in Render’s dashboard:
| Key | Value |
|---|---|
PORT | 8080 |
SPRING_DATASOURCE_URL | jdbc:postgresql://<render-db-host>:5432/<dbname> |
SPRING_DATASOURCE_USERNAME | <dbuser> |
SPRING_DATASOURCE_PASSWORD | <dbpass> |
APP_JWT_SECRET | change-this-to-a-strong-secret |
Database name: blogdb_xz40 User: postgresuser Hostname: dpg-d3ck3ondiees738267q0-a Port: 5432 External URL: postgresql://postgresuser:<password>@dpg-d3ck3ondiees738267q0-a.oregon-postgres.render.com/blogdb_xz40 Base URL: 🔗 https://blogpostspringboot.onrender.com/
Swagger Docs: 🔗 https://blogpostspringboot.onrender.com/swagger-ui/index.html
src └── main ├── java/com/example/BlogPostSpringBoot │ ├── controller/ → REST controllers │ ├── service/ → Business logic │ ├── repository/ → Spring Data JPA repositories │ ├── model/ → Entity classes │ ├── security/ → JWT & SecurityFilterChain │ └── BlogPostSpringBootApplication.java └── resources/ ├── application.properties └── static/templates (if used) - Add Flyway migrations for auto schema setup.
- Add pagination and search to blog endpoints.
- Implement comment system.
- Integrate email verification on registration.
- Deploy a frontend React app connected to this API.
Shuvo Joseph Founder of DeshiIT 💼 Full-Stack & iOS Developer | Backend (Spring Boot, .NET Core, NestJS, Laravel) 📧 Contact: LinkedIn