Important
这是一个基于 Spring Boot 和微服务架构构建的生产级模板项目。虽然它展示了行业最佳实践,但在部署到生产环境之前,请务必全面审查和加强安全措施。
这是一个基于 Spring Boot 的综合性电商平台模板,采用微服务架构。该项目为构建可扩展的在线购物应用程序提供了强大的基础,整合了行业标准实践和现代技术。
- 🏗️ 微服务架构 - 基于 Spring Cloud Alibaba 构建
- 🔐 安全系统 - JWT 和 OAuth2 集成
- 📦 数据管理 - 支持 JPA 和 MyBatis
- 💾 缓存方案 - Redis 集成
- 📨 消息队列 - RabbitMQ 实现
- 🔄 网关 - Spring Cloud Gateway
- ⚙️ 服务发现 - Spring Cloud Eureka
- 🤖 AI 集成 - 已具备 AI 功能开发准备
- ⏰ 任务调度 - Quartz 实现
- 📧 邮件服务 - Spring Mail 支持
Important
开始之前,请确保已安装以下软件:
- JDK 17 或更高版本
- Maven 3.6+
- MySQL 5.7+
- IntelliJ IDEA (推荐)
- Git
使用 IntelliJ IDEA 创建项目
- 打开 IntelliJ IDEA
- 点击"新建项目"
- 选择"Spring Initializr"
- 配置项目元数据:
Group: com.douyinmall Artifact: douyin-mall-java-template Name: douyin-mall-java-template Description: 抖音商城 Java 模板项目 Package name: com.douyinmall.mall Packaging: Jar Java version: 17
选择依赖
- Spring Web
- Spring Boot DevTools
- Lombok
- Spring Configuration Processor
- Spring Data JPA
- MySQL Driver
- Spring Data Redis
- MyBatis Framework
- Spring Security
- OAuth2 Resource Server
- Spring Session
- Spring for RabbitMQ
- Eureka Discovery Client
- Config Client
- Gateway
- Resilience4j
- Spring Boot Actuator
- Validation
- Java Mail Sender
- Quartz Scheduler
在 src/main/resources
中创建 application.properties
:
# 应用
spring.application.name=douyin-mall
server.port=8080
# 数据库
spring.datasource.url=jdbc:mysql://localhost:3306/douyin_mall?useUnicode=true&characterEncoding=utf8&serverTimezone=Asia/Shanghai
spring.datasource.username=root
spring.datasource.password=your_password
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
# JPA
spring.jpa.database-platform=org.hibernate.dialect.MySQLDialect
spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=update
spring.jpa.open-in-view=false
# 初始禁用服务
spring.autoconfigure.exclude=\
org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration,\
org.springframework.boot.autoconfigure.data.redis.RedisRepositoriesAutoConfiguration,\
org.springframework.boot.autoconfigure.amqp.RabbitAutoConfiguration
# Eureka Client
eureka.client.enabled=false
CREATE DATABASE douyin_mall CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
📦douyin-mall-java-template
┣ 📂src
┃ ┣ 📂main
┃ ┃ ┣ 📂java
┃ ┃ ┃ ┗ 📂com
┃ ┃ ┃ ┃ ┗ 📂douyinmall
┃ ┃ ┃ ┃ ┃ ┗ 📂mall
┃ ┃ ┃ ┃ ┃ ┃ ┗ 📜DouyinMallJavaTemplateApplication.java
┃ ┃ ┗ 📂resources
┃ ┃ ┃ ┣ 📂static
┃ ┃ ┃ ┣ 📂templates
┃ ┃ ┃ ┗ 📜application.properties
┃ ┗ 📂test
┃ ┃ ┗ 📂java
┃ ┃ ┃ ┗ 📂com
┃ ┃ ┃ ┃ ┗ 📂douyinmall
┃ ┃ ┃ ┃ ┃ ┗ 📂mall
┃ ┃ ┃ ┃ ┃ ┃ ┗ 📜DouyinMallJavaTemplateApplicationTests.java
┣ 📂target
┃ ┣ 📂classes
┃ ┣ 📂generated-sources
┃ ┣ 📂generated-test-sources
┃ ┗ 📂test-classes
┣ 📜.gitattributes
┣ 📜.gitignore
┣ 📜CODE_OF_CONDUCT.md
┣ 📜HELP.md
┣ 📜LICENSE
┣ 📜mvnw
┣ 📜mvnw.cmd
┣ 📜pom.xml
┗ 📜README.md
# 构建项目
mvn clean package
# 运行应用
java -jar target/douyin-mall-java-template-0.0.1-SNAPSHOT.jar
直接在 IDE 中运行主类 DouyinMallApplication.java
。
Tip
如果遇到 JDK 版本问题:
- 验证 JDK 17 安装情况
- 检查项目结构设置
- 确认 Maven 编译器设置
Note
常见数据库连接问题:
- MySQL 服务状态
- 数据库凭证
- 数据库是否存在
- 端口可用性
如果端口 8080 被占用,请修改 application.properties 中的 server.port
。
- Fork 本仓库
- 创建特性分支 (
git checkout -b feature/AmazingFeature
) - 提交更改 (
git commit -m '添加一些功能'
) - 推送到分支 (
git push origin feature/AmazingFeature
) - 提交 Pull Request
本项目采用 Apache-2.0 许可证 - 详见 LICENSE.md 文件。
Chan Meng
LinkedIn: chanmeng666
GitHub: ChanMeng666
用 ❤️ 为 Java 开发者打造
⭐ 在 GitHub 上为我们点星 | 📖 阅读文档 | 🐛 报告问题
⭐ 在 GitHub 上为我们点星 | 📖 阅读文档 | 🐛 报告问题