A Spring Boot backend system for managing users, roles, products, and orders.
- Java 11 or higher
- Maven 3.6+
- MySQL 8.0+ (or MySQL 5.7+)
Ubuntu/Debian:
sudo apt update
sudo apt install mysql-server
sudo mysql_secure_installationmacOS:
brew install mysql
brew services start mysqlWindows: Download and install from MySQL Downloads
Linux:
sudo systemctl start mysql
sudo systemctl enable mysqlmacOS:
brew services start mysqlWindows: MySQL service should start automatically after installation.
Login to MySQL:
mysql -u root -pThen create the database:
CREATE DATABASE enterprise_db;
SHOW DATABASES;
EXIT;Edit src/main/resources/application.properties:
spring.datasource.url=jdbc:mysql://localhost:3306/enterprise_db?useSSL=false&serverTimezone=UTC&allowPublicKeyRetrieval=true
spring.datasource.username=root
spring.datasource.password=YOUR_MYSQL_PASSWORDImportant: Replace YOUR_MYSQL_PASSWORD with your actual MySQL root password.
Test connection:
mysql -u root -p -e "USE enterprise_db; SHOW TABLES;"# Navigate to project directory
cd enterprise-user-order-system
# Build the project
mvn clean install
# Run the application
mvn spring-boot:runThe application will:
- ✅ Automatically create database tables (via
spring.jpa.hibernate.ddl-auto=update) - ✅ Create ADMIN and USER roles on startup
- ✅ Start on
http://localhost:8080
Once running, open:
http://localhost:8080/swagger-ui/index.html
POST /api/auth/register- Register a new userPOST /api/auth/login- Login and get JWT token
GET /api/products- List products (paginated)GET /api/products/search?q=name- Search productsGET /api/products/{id}- Get product by IDPOST /api/products- Create product (ADMIN only)PUT /api/products/{id}- Update product (ADMIN only)DELETE /api/products/{id}- Delete product (ADMIN only)
POST /api/orders- Create orderGET /api/orders/me- Get current user's ordersGET /api/orders- Get all orders (ADMIN only)PUT /api/orders/{id}/status- Update order status (ADMIN only)
GET /api/admin/users- Get all users
-
Register a user:
POST http://localhost:8080/api/auth/register Content-Type: application/json { "username": "testuser", "email": "test@example.com", "password": "password123" } -
Login:
POST http://localhost:8080/api/auth/login Content-Type: application/json { "usernameOrEmail": "testuser", "password": "password123" }Copy the
tokenfrom the response. -
Use token in subsequent requests:
Authorization: Bearer <your_token_here>
The application automatically creates these tables:
users- User accountsroles- User roles (ADMIN, USER)products- Product catalogorders- Customer ordersorder_items- Order line items
- Ensure MySQL is running:
sudo systemctl status mysql - Check MySQL port:
netstat -an | grep 3306
- Verify username/password in
application.properties - Reset MySQL password if needed:
ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password'; FLUSH PRIVILEGES;
- Create it manually:
CREATE DATABASE enterprise_db;
- Change port in
application.properties:server.port=8081
- Roles (ADMIN, USER) are automatically created on first startup
- JWT tokens expire after 1 hour (configurable in
application.properties) - Database tables are auto-created/updated via Hibernate
- For production, change
spring.jpa.hibernate.ddl-autotovalidateornone