This is a backend project for Type Shi(f)t Arena. It is a simple project that uses Spring Boot and Spring Data JPA to manage a MySQL database.
In the development environment, database and JWT configurations use environment variables to prevent privacy leaks.
The specific code is as follows:
# application-dev.properties
......
spring.datasource.url=${MYSQL_URL:jdbc:mysql://localhost:3306/myappdb}
spring.datasource.username=${MYSQL_USERNAME}
spring.datasource.password=${MYSQL_PASSWORD}
.....
.....
jwt.secret=${JWT_SECRET:your_jwt_secret_key_should_be_at_least_256_bits_long_for_security}
jwt.expiration=${JWT_EXPIRATION:86400}
For Windows:
- Right-click "This PC" -> Properties
- Click "Advanced system settings"
- Click "Environment Variables" button
- Click "New" in the "System Variables" section
- Add the following variables:
MYSQL_USERNAME=your_database_username
MYSQL_PASSWORD=your_password
JWT_SECRET=your_secret_key (optional)
JWT_EXPIRATION=your_desired_expiration_time (optional)
For Mac:
- Open configuration file
nano ~/.zshrc - Add the following content:
export MYSQL_USERNAME=your_database_username
export MYSQL_PASSWORD=your_password
export JWT_SECRET=your_secret_key (optional)
export JWT_EXPIRATION=your_desired_expiration_time (optional)
- Save and exit the file
- Reload configuration with source ~/.zshrc
- Spring Boot 3.2.3
- Maven 3.9.9
- MySQL 9.0.1
- JDK 17
- JWT
- Spring Security
- Spring WebSocket
To initialize the database, follow these steps:
-
Ensure you have MySQL installed and running.
-
Open a MySQL client (e.g., MySQL Workbench or command-line client).
-
Run the SQL script located at
sql/init.sql. This will create the database and necessary tables.You can do this by running the following command in your MySQL client:
source /path/to/your/project/sql/init.sql -
Update the
application-dev.propertiesandapplication-prod.propertiesfiles with your database credentials.
To run the application, use the following command. (Default is development environment)
for development:
mvn spring-boot:runfor production:
mvn spring-boot:run -Dspring.profiles.active=prodvisit http://localhost:9090/hello to see the result.
visit http://localhost:9090/swagger-ui.html to see the API documentation and test the API.
waring: some API may not work because of the security configuration.