This is the runthrough of the YT-Tutorial "Fullstack Developement with Java Spring Boot, React and MongoDB" Hosted by freeCodeCamp.org.
Teachers:
Backend: Farhan Hasin Chodhury
Frontend: Gavin Lon @GavinLon
See the original Code on the following repos:
Backend: https://github.com/fhsinchy/movieist\
Frontend: https://github.com/GavinLonDigital/movie-gold-v1
I just run through the first part of the tutorials. The backend is done by me. With the React-part/ Frontend I had trouble to follow along, because it is more a codealong, than a tutorial.
- Hava Java JDK LTS installed (by this Date 21.01.2023 I used JDK 17) Link: https://www.oracle.com/java/technologies/downloads/#jdk17-windows
- Have an account at MongoDB Atlas https://cloud.mongodb.com
- Install MongoDB Compass for easyaccess to DB
- I use the VSCode-Editor with the following extensions Extension Pack for Java (there will be additional extensions installed, which I don't write down here), Maven for Java, Bracket Pair Colorization Tool, Error Lens, MongoDB for VS Code, One Dark Pro, vscode-icons, XML Tools
- Go to https://cloud.mongodb.com and create a new vluster
- use a shared one, with the minimum requirements it fits best for developing purposes. Using more power on the cloud will cost some bucks, so choose wisley.
- Go to https://start.spring.io/
- On the left side edit the project like needed In this project I went for a Maven-Project in Java and used the Spring Boot Version 3.0.1 The project metadata is selfexplaining: group = com.example artefact = name of application
I went for packaging-format jar and since I installed JDK 17 Java is 17
-
On the right side I choose some dependencies I wanted preselected in the jar-File: I went for Lombok, Sping Weg, Sping Data MongoDB and Spring Boot DevTools
-
Wit Generate the project-zip gets generated and downloaded.
-
unzip it in the project folder and open it with VSC
- Error 8080 is blocked by an running process 1- run netstat -ano to get pid number 2- run taskname /fi “pid eq ” 3- run taskkill /f /PID
- Error Whitlabelpage 1- no routes are set in the project 2- wit GetMapping and RestController Annotation Routes can be set to the application
- spring.data.mongodb.database=
- spring.data.mongodb.uri=
- Spring don't support reading env-Files
1- add new dependecy
2- look at maven repositories for a fitting one
3- Add Dependency in pom.xml under dependencies with groupId (com.example), artifactI(name of repo) and version
4- With the dependency from paul schwarz you can access env-Variables by
${env.} 5- spring.data.mongodb.database=$ {env.MONGO_DATABASE} spring.data.mongodb.uri= mongodb+srv://${env.MONGO_USER}:${env.MONGO_PASSWORD}@${env.MONGO_CLUSTER}
- in java/de/mikedilexa/movies create the classes Movie.java and Review.java
- For referencing relationships use @DocumentReference 1- look at mongodb reference relationships and do some research
- Create MovieController.java class
- Requests against an API are done with REST and the urls 1- Use @RestController and @RequestMapping()
1. Needed: a service class and a repository class
In RestApis are multiple Layers
Controller: Get Request and give a Response
Service: use repository and talks to DB
Repository: Access-Layer to DB and get Data back
- In Service Class all the possible Services gets implemented (eg. get all movies, get a movie by id, and so on)
- In Repository class just the MongoRepository-Class wie Movie and ObjectId gets extended
- get Data by some other filed than ObjectID --> Do not reveal this to public By defining the string "Optional findMovieByImdb(String imdbId);" in the repository-class MongoDB finds everything to get the requested movie
- taking new mongo template
- using update movie with new review
- push the new review to the repository
Create a new Review Controller