Spring Boot + MySQL + Docker + Render Deployment Guide
Step 1: Create Spring Boot Project
- Use https://start.spring.io
- Dependencies: Spring Web, Spring Data JPA, MySQL Driver
- Java version: 17
Step 2: Build Your CRUD App
- Create User.java (model with fields, getters/setters)
- Create UserRepository.java (JPA Repository)
- Create UserController.java (CRUD REST API endpoints)
Step 3: Configure MySQL Connection
- In application.properties:
- spring.datasource.url=jdbc:mysql://<host>:<port>/<db>
- spring.datasource.username=<username>
- spring.datasource.password=<password>
- spring.jpa.hibernate.ddl-auto=update
Step 4: Set Up Cloud MySQL (Railway)
- Go to https://railway.app
- Create project -> Provision MySQL
- Copy DB credentials and use in application.properties
Step 5: Add Docker Support
- Create Dockerfile with multi-stage build
- Use Maven image to build .jar, then run with JDK image
Step 6: Push Project to GitHub
- git init
- git add .
- git commit -m 'Initial commit'
- git remote add origin <your-repo-url>
- git push -u origin main
Step 7: Deploy on Render
- Go to https://render.com
- Create new Web Service and connect GitHub
- Choose Docker runtime, set port 8081
Step 8: Test Everything
- Use browser, frontend, or Postman to test:
- GET /users, POST /users, PUT /users/{id}, DELETE /users/{id}
- Data is saved and fetched from Railway MySQL