Inspired from the original repo with SpringBoot + MyBatis + ReactJS. A detailed tutorial of the original repository can be found at the link here.
This Java 11 project provides the following functionalities.
- The backend was implemented with the latest version of Spring Boot, v2.7.2. The deprecated APIs in previous versions were not used in this project.
- Basic CRUD operations were implemented with the help of PostgreSQL and MyBatis. The system maintains the information of clients in a Client List.
- Login, Log out and Register were implemented with Spring Security (under the folder
src/main/java/com/jasonqiu/springbootreactdemo).- Login was implemented with JWT + Redis.
- Redis helps store the key-value pair of (
JWT:UserDetails) every time the login is successful. - When the user logs out, this key-value pair will be deleted from Redis. The login is valid for one hour.
- Redis helps store the key-value pair of (
- Sending verification code was mocked by outputting to the console.
- Check the console log of
springboot-appto get the token if you need :) The verification code is valid for five minutes.
- Check the console log of
- Three authorities were defined in the system,
admin,userandguest.- The three authorities have different sets of permissions to the system.
- Login was implemented with JWT + Redis.
- The frontend was purely implemented in React 18.
- All the (UI) components were borrowed from Material UI. No additional CSS files were involved.
- So you'll see a system similar to the simplest MUI websites.
- React Router v6 (the latest version) was used in this project.
- The (latest) recommended usage of Redux was adopted in this project.
- Some certain buttons (e.g. Delete) were debounced using a self-defined hook
useDebounce(borrowed somewhere from the Internet)
- All the (UI) components were borrowed from Material UI. No additional CSS files were involved.
- The project was deployed by Docker containers (with Dockerfile and docker-compose.yml). It includes five containers.
demo-frontenddeploys the frontend build (container_name: react-app)demo-backenddeploys the backend .jar package (container_name: springboot-app)dbdeploys the PostgreSQL 14.4 image and inits with the databasedemo_db(container_name: postgres2)redis-masterdeploys a Redis master node from Redis 7.0 (container_name: myredis)redis-replicadeploys a Redis replica (container_name: myredis-replica)
Make sure the Docker daemon is running on your machine, and simply run the script run.sh with the following command line.
sh run.shIf there is no error, enter http://localhost:3000 in your browser, and you can access our Client List. The stdout should end with messages like the following:
springboot-app | 2022-09-22 22:33:25.266 INFO 1 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8091 (http) with context path ''
springboot-app | 2022-09-22 22:33:25.279 INFO 1 --- [ main] c.j.s.SpringbootReactDemoApplication : Started SpringbootReactDemoApplication in 3.692 seconds (JVM running for 4.038)
If there is any error, consider the following issues.
- Dependency issues. Check if the Docker daemon process is running. If yes, then check whether certain versions of the docker images defined in
docker-compose.yml,Dockerfileorfrontend/Dockerfilehave been deprecated. Update them to thelatestversion or an available version of your choice, if necessary. - It might be the case your local machine already has some containers with the same names. In this case, consider comment the specific lines of
container_namein the file docker-compose.yml where the name has already been taken by your local machine.
I have provided two default username and password combinations.
- An
adminaccount- username:
admin, password:helloworld
- username:
- A
useraccount- username:
jasonqiu, password:helloworld
- username:
- You can register your own account, and then the account becomes a
guestaccount.
You can use docker compose start to quickly re-run this project without building the apps again.
You can start a new terminal window and run docker compose stop to stop all the services, and then docker compose down -v (short for docker compose down --volumes) to remove all the containers, networks and volumes generated by the docker-compose.yml file. You need to manually remove the images created by the shell script.
Enjoy!