STEP 1: Create Spring Boot Web Project
From your IDE:
-
Create New Spring Starter Project
-
Select Web
-
Create packages:
STEP 2: Initialize Firebase
Create class in dbinit package:
@PostConstruct ensures the method runs automatically on app startup.
STEP 3: Firebase Login & Firestore Setup
-
Open Firebase Console
-
Choose Cloud Firestore
-
Click Start Collection
-
Collection ID:
beginner -
Document ID: anything (e.g.,
xyz123) -
Field example:
id = "xyz123"
Document ID can be auto-generated or same as your model's ID.
STEP 4: Firestore Connection Code
Go to:
Project Settings → Service Accounts → Java → Generate Code
Copy the code snippet provided.
STEP 5: Initialize Firebase in Project
Paste code inside initializeFirebase():
STEP 6: Add Firebase Dependencies
-
Go to Maven Repository
-
Search firebase-admin
-
Use a compatible version (example:
6.11.0) -
Add in
pom.xml -
Import Firebase classes
STEP 7: Generate Private Key
In Service Accounts:
-
Click Generate New Private Key
-
Download the
.jsonfile -
Paste it inside the project root
-
Replace:
STEP 8: Create Model – Student
Fields:
Generate:
-
constructors
-
getters/setters
-
toString()
STEP 9: Create home.jsp
Path: src/main/webapp/home.jsp
STEP 10: Controller Setup
STEP 11: Add Tomcat Jasper (for JSP)
If page doesn’t load, add Tomcat Jasper:
-
Search tomcat-embed-jasper
-
Version must match
tomcat-embed-core -
Add dependency to
pom.xml
STEP 12: Relaunch Project
Now JSP loads properly at:
STEP 13: Controller Save Method
Console prints "successfully saved" → Controller working.
STEP 14: Create Service Class
STEP 15: Firebase Code to Save Data
STEP 16: Call Service From Controller
STEP 17: Add Data to Firebase
-
Relaunch project
-
Submit form
-
Check Firestore
→ Data stored successfully
STEP 18: Push Project to GitHub
Commands:
STEP 19: Deploy Spring Boot App to Heroku
-
Login to Heroku
-
Create New App
Example:test -
Connect to GitHub
-
Authorize (first time only)
-
Select repository
-
Enable Automatic Deploy
-
Click Deploy Branch
-
After deployment → Heroku gives URL
Example:
Your project is now LIVE.
✔ End
-- Thanks --
Great
ReplyDelete