fix: 修复网关启动找不到服务的问题,修复jwt问题,修复自动导入失败问题。

This commit is contained in:
2025-12-14 15:02:24 +08:00
parent 4912e48922
commit 63d0528af4
33 changed files with 792 additions and 421 deletions

251
CLAUDE.md
View File

@@ -2,195 +2,122 @@
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
## Project Overview
## Codebase Overview
This is a microservices-based Online Judge (OJ) system with AI integration called AIOJ (AI Online Judge). It's built with Spring Boot 3.5.7 and Spring Cloud 2025.0.0, following a modular Maven multi-module architecture.
This is a microservices architecture for an Online Judge (OJ) system, built on **Spring Boot 3.5.7**. The project uses Maven as the build tool and follows a modular monorepo structure, with clearly separated core modules and service modules.
## Common Development Commands
### Core Modules
### Building the Project
```bash
# Build entire project
mvn clean install
The `aioj-backend-common` directory contains shared components and utilities used across all service modules:
# Build with specific environment profile
mvn clean install -P dev # Development (default)
mvn clean install -P test # Testing
mvn clean install -P prod # Production
1. **aioj-backend-common-bom**
Bill of materials for centralized dependency management. This ensures consistent versions of all external libraries across all modules.
# Format code according to Spring standards
mvn spring-javaformat:apply
2. **aioj-backend-common-core**
Core utilities and Spring framework extensions:
- `BannerApplicationRunner`: Custom application banner display during startup
- `SpringContextHolder`: Spring context accessor for non-Spring-managed classes
- `JavaTimeModule`: Jackson module for Java 8+ time API support
- Common constants and enumerations
- Application-level configurations and auto-configuration classes
# Build Docker images using Jib
mvn clean package jib:build
3. **aioj-backend-common-feign**
Feign client configurations for seamless inter-service communication:
- Auto-configuration for Feign clients with default settings
- `@EnableAIOJFeignClients` annotation for enabling Feign clients with predefined base packages
- Feign interceptors and error handling mechanisms
# Or use Maven wrapper
./mvnw clean install
```
4. **aioj-backend-common-log**
Aspect-oriented programming (AOP) based logging framework:
- `SysLogAspect`: Aspect for logging system operations (controller methods, service calls)
- `SysLogEvent` and `SysLogListener`: Event-driven logging mechanism
- `SysLogUtils`: Utility class for creating and managing log entries
- Configuration properties for logging behavior
### Running Services
Each service runs on different ports:
- Gateway: 8085
- Other services: configured via Nacos
5. **aioj-backend-common-mybatis**
MyBatis ORM framework extensions:
- Auto-fill functionality for `createTime` and `updateTime` fields
- Pagination interceptor implementation
- MyBatis configuration auto-configuration classes
Run individual services from their respective directories:
```bash
cd aioj-backend-gateway
mvn spring-boot:run
6. **aioj-backend-common-starter**
Auto-configuration starters for easily enabling common features in service modules.
# Or with specific profile
mvn spring-boot:run -Dspring.profiles.active=dev
```
### Database Setup
1. Create databases using the provided script:
```bash
mysql -u root -p < db/create_db.sql
```
This creates three databases: `aioj_dev`, `aioj_test`, and `aioj_prod`
### Service Modules
## Architecture Overview
The service modules represent the individual microservices that make up the system:
### Microservices Architecture
The system consists of seven main services:
1. **aioj-backend-auth**
Authentication and authorization service:
- JWT-based authentication with `JwtAuthenticationFilter`
- Security configuration with Spring Security
- User login, token generation, and validation
- Permission verification and access control
1. **aioj-backend-gateway** (Port 8085)
- API Gateway using Spring Cloud Gateway
- Routes requests to appropriate services
- Built with WebFlux for reactive programming
2. **aioj-backend-gateway**
API gateway for request routing and filtering:
- Request routing to appropriate service modules
- Authentication token validation before forwarding requests
- Rate limiting and request filtering mechanisms
2. **aioj-backend-auth**
- OAuth2 authentication and authorization service
- Manages user credentials and tokens
3. **aioj-backend-judge-service**
Code judge service (under development):
- Will handle code submission, compilation, and execution
- Support for multiple programming languages
- Test case validation and result return
3. **aioj-backend-user-service**
- User management and profiles
- Handles registration, login, profile updates
- Integrates with Redis for session management
4. **aioj-backend-user-service**
User management service:
- User registration, profile management, and information retrieval
- User role and permission assignment
- Integration with the auth service for authentication
4. **aioj-backend-question-service**
- Problem/question management
- Handles problem storage and retrieval
5. **aioj-backend-judge-service**
- Core OJ functionality for code execution
- Supports multiple programming languages
5. **aioj-backend-question-service**
Question bank service (under development):
- Will manage programming problems, test cases, and problem categories
- Support for problem difficulty levels and tags
- Integration with the judge service for problem submission
6. **aioj-backend-ai-service**
- AI integration for enhanced features
- Code analysis and automated feedback
AI-related functionality service (under development):
- Will provide AI-assisted features like problem recommendation, code analysis, etc.
7. **aioj-backend-upms** (User Permission Management System)
- Role-based access control
- Permission management
7. **aioj-backend-upms**
User, permission, and menu management service:
- Low-level user and permission management
- Menu and resource access control
- Integration with other services for authorization
### Common Modules
- **aioj-backend-common**: Shared utilities with sub-modules:
- `core`: Core utilities and configurations
- `log`: Custom logging implementation
- `starter`: Auto-configuration starters
- `mybatis`: Database access layer
- `feign`: HTTP client for service communication
- `bom`: Bill of Materials for dependency management
## Commonly Used Commands
## Technology Stack
### Core Technologies
- **Java 17**
- **Spring Boot 3.5.7**
- **Spring Cloud 2025.0.0**
- **Spring Cloud Alibaba 2025.0.0.0**
- **Maven** for build management
### Database & Persistence
- **MySQL 9.4.0** as primary database
- **MyBatis-Plus 3.5.14** for ORM
- **Redis** for caching and session management
### Cloud & Infrastructure
- **Nacos** for service discovery and configuration (server: 10.0.0.10:8848)
- **Spring Cloud Gateway** for API routing
- **Docker** with Jib plugin for containerization
- **Sentinel** for circuit breaking
### Security
- **Spring Security 6.5.6** with OAuth2
- JWT token-based authentication
- Role-based access control
### API Documentation
- **Knife4j** (OpenAPI 3) integrated across services
## Configuration Management
### Environment-Specific Configuration
Three environments are supported:
- `dev` (development, default)
- `test` (testing)
- `prod` (production)
Configuration files:
- `bootstrap.yml` - Nacos service discovery configuration
- `application.yml` - Main application configuration
- `application-{env}.yml` - Environment-specific settings
### Nacos Integration
All services use Nacos for:
- Service discovery
- Configuration management
- Centralized properties management
Default Nacos configuration:
```yaml
spring:
cloud:
nacos:
discovery:
server-addr: 10.0.0.10:8848
username: nacos
password: nacos
```
## Database Schema
### Environment Databases
- Development: `aioj_dev`
- Testing: `aioj_test`
- Production: `aioj_prod`
All databases use UTF-8 character set with `utf8mb4_general_ci` collation.
## Development Guidelines
### Build
- **Build the entire project**: `mvn clean compile`
- **Build with tests**: `mvn clean install`
- **Build a single module**: `mvn clean compile -pl aioj-backend-auth`
### Code Formatting
- Uses Spring JavaFormat plugin for consistent code style
- IDE plugin available: https://repo1.maven.org/maven2/io/spring/javaformat/spring-javaformat-intellij-idea-plugin
- Run `mvn spring-javaformat:apply` before commits
- **Format code**: `mvn spring-javaformat:apply`
- **Check code format**: `mvn spring-javaformat:check`
### Docker Integration
- Jib plugin configured for container builds
- Target registry: `10.0.0.3/aioj/{service-name}:{version}`
- JVM memory configured: -Xms512m -Xmx512m
### Testing
- **Run all tests**: `mvn test`
- **Run tests for a single module**: `mvn test -pl aioj-backend-user-service`
### Service Communication
- Uses OpenFeign for inter-service communication
- Load balancing with Spring Cloud LoadBalancer
- Circuit breaking with Sentinel
### Running Services
- **Run a service locally**: Use Spring Boot's `Application` class directly in IDE or use `mvn spring-boot:run -pl <module-name>`
- **Example**: `mvn spring-boot:run -pl aioj-backend-auth`
### Logging
- Custom logging implementation in `aioj-backend-common-log`
- Integrates with Spring Security for context logging
- Uses Hutool utilities for enhanced logging
## Architecture Highlights
## Testing
- Spring Boot Test framework included
- Spring Security Test for authentication testing
- Test structure is evolving - check individual modules for test coverage
- **Authentication**: JWT-based authentication implemented in `aioj-backend-auth` with `JwtAuthenticationFilter`
- **Logging**: Aspect-oriented logging with `SysLogAspect` in `aioj-backend-common-log`
- **Database**: MyBatis with auto-fill for create/update times implemented in `common-mybatis`
- **Inter-service communication**: Feign clients with auto-configuration from `common-feign`
- **Banner**: Custom application banner system in `common-core`
## Important Notes
## Key Entry Points
1. **Service Dependencies**: Services depend on Nacos for discovery - ensure Nacos is running before starting services
2. **Database Setup**: Run the database creation script before first run
3. **Port Configuration**: Gateway runs on 8085, other services are dynamically registered
4. **Environment Profiles**: Default is `dev` - use appropriate profiles for different environments
5. **Configuration Management**: Most configuration is externalized to Nacos - check Nacos for service-specific settings
- **Gateway Application**: `aioj-backend-gateway/src/main/java/cn/meowrain/aioj/backend/gateway/AIOJGatewayApplication.java`
- **Auth Application**: `aioj-backend-auth/src/main/java/cn/meowrain/aioj/backend/auth/AIOJAuthApplication.java`
- **User Service Application**: `aioj-backend-user-service/src/main/java/cn/meowrain/aioj/backend/userservice/UserServiceApplication.java`