996 lines
27 KiB
Markdown
996 lines
27 KiB
Markdown
# 基于Spring Cloud的高可用在线视频平台项目架构
|
|
|
|
## 技术栈选型
|
|
|
|
根据2024年最新技术栈和Spring Cloud Alibaba 2023.0.1.0版本,选用以下组件:
|
|
|
|
- **框架基础**:
|
|
- Spring Boot 3.2.4
|
|
- Spring Cloud 2023.0.1
|
|
- Spring Cloud Alibaba 2023.0.1.0
|
|
|
|
- **核心组件**:
|
|
- Nacos 2.3.2 (服务注册与配置中心)
|
|
- Sentinel 1.8.6 (流量控制)
|
|
- Seata 2.0.0 (分布式事务)
|
|
- RocketMQ 5.1.4 (消息队列)
|
|
|
|
- **其他组件**:
|
|
- Spring Cloud Gateway (API网关)
|
|
- OpenFeign (服务调用)
|
|
- Spring Security + OAuth2 + JWT (安全认证)
|
|
- MySQL 8.0 (主数据库)
|
|
- Redis 7.0 (缓存)
|
|
- MinIO (分布式文件存储)
|
|
- FFmpeg (视频处理)
|
|
- Prometheus + Grafana (监控)
|
|
- Docker + DockerCompose (容器化部署)
|
|
|
|
## IntelliJ IDEA 创建步骤
|
|
|
|
### 1. 创建父工程 (Maven项目)
|
|
|
|
1. 打开IntelliJ IDEA,选择"File" -> "New" -> "Project"
|
|
2. 选择"Maven",点击"Next"
|
|
3. 填写项目信息:
|
|
- GroupId: `com.nuaa.video`
|
|
- ArtifactId: `video-platform`
|
|
- Version: `1.0.0`
|
|
4. 点击"Finish"创建项目
|
|
|
|
5. 修改父工程pom.xml:
|
|
|
|
```xml
|
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
|
<modelVersion>4.0.0</modelVersion>
|
|
<parent>
|
|
<groupId>org.springframework.boot</groupId>
|
|
<artifactId>spring-boot-starter-parent</artifactId>
|
|
<version>3.2.4</version>
|
|
<relativePath/>
|
|
</parent>
|
|
|
|
<groupId>com.nuaa.video</groupId>
|
|
<artifactId>video-platform</artifactId>
|
|
<version>1.0.0</version>
|
|
<packaging>pom</packaging>
|
|
<name>video-platform</name>
|
|
<description>基于Spring Cloud的高可用在线视频平台</description>
|
|
|
|
<properties>
|
|
<java.version>17</java.version>
|
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
|
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
|
<spring-cloud.version>2023.0.1</spring-cloud.version>
|
|
<spring-cloud-alibaba.version>2023.0.1.0</spring-cloud-alibaba.version>
|
|
</properties>
|
|
|
|
<dependencyManagement>
|
|
<dependencies>
|
|
<!-- Spring Cloud -->
|
|
<dependency>
|
|
<groupId>org.springframework.cloud</groupId>
|
|
<artifactId>spring-cloud-dependencies</artifactId>
|
|
<version>${spring-cloud.version}</version>
|
|
<type>pom</type>
|
|
<scope>import</scope>
|
|
</dependency>
|
|
|
|
<!-- Spring Cloud Alibaba -->
|
|
<dependency>
|
|
<groupId>com.alibaba.cloud</groupId>
|
|
<artifactId>spring-cloud-alibaba-dependencies</artifactId>
|
|
<version>${spring-cloud-alibaba.version}</version>
|
|
<type>pom</type>
|
|
<scope>import</scope>
|
|
</dependency>
|
|
</dependencies>
|
|
</dependencyManagement>
|
|
|
|
<modules>
|
|
<module>video-common</module>
|
|
<module>video-gateway</module>
|
|
<module>video-auth</module>
|
|
<module>video-user</module>
|
|
<module>video-content</module>
|
|
<module>video-comment</module>
|
|
<module>video-recommend</module>
|
|
<module>video-admin</module>
|
|
</modules>
|
|
|
|
<build>
|
|
<plugins>
|
|
<plugin>
|
|
<groupId>org.springframework.boot</groupId>
|
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
|
</plugin>
|
|
<plugin>
|
|
<groupId>org.apache.maven.plugins</groupId>
|
|
<artifactId>maven-compiler-plugin</artifactId>
|
|
<configuration>
|
|
<source>${java.version}</source>
|
|
<target>${java.version}</target>
|
|
<encoding>${project.build.sourceEncoding}</encoding>
|
|
</configuration>
|
|
</plugin>
|
|
</plugins>
|
|
</build>
|
|
</project>
|
|
```
|
|
|
|
### 2. 创建公共模块 (video-common)
|
|
|
|
1. 右键父工程 -> New -> Module
|
|
2. 选择"Maven",点击"Next"
|
|
3. 填写模块信息:
|
|
- Name: `video-common`
|
|
- Parent: `com.nuaa.video:video-platform`
|
|
4. 点击"Finish"
|
|
|
|
5. 修改video-common的pom.xml:
|
|
|
|
```xml
|
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
|
<parent>
|
|
<artifactId>video-platform</artifactId>
|
|
<groupId>com.nuaa.video</groupId>
|
|
<version>1.0.0</version>
|
|
</parent>
|
|
<modelVersion>4.0.0</modelVersion>
|
|
|
|
<artifactId>video-common</artifactId>
|
|
|
|
<dependencies>
|
|
<!-- Lombok -->
|
|
<dependency>
|
|
<groupId>org.projectlombok</groupId>
|
|
<artifactId>lombok</artifactId>
|
|
<optional>true</optional>
|
|
</dependency>
|
|
|
|
<!-- Spring Boot Starter Web -->
|
|
<dependency>
|
|
<groupId>org.springframework.boot</groupId>
|
|
<artifactId>spring-boot-starter-web</artifactId>
|
|
</dependency>
|
|
|
|
<!-- Spring Boot Starter Validation -->
|
|
<dependency>
|
|
<groupId>org.springframework.boot</groupId>
|
|
<artifactId>spring-boot-starter-validation</artifactId>
|
|
</dependency>
|
|
|
|
<!-- Spring Cloud Alibaba Nacos Discovery -->
|
|
<dependency>
|
|
<groupId>com.alibaba.cloud</groupId>
|
|
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
|
|
</dependency>
|
|
|
|
<!-- Spring Cloud OpenFeign -->
|
|
<dependency>
|
|
<groupId>org.springframework.cloud</groupId>
|
|
<artifactId>spring-cloud-starter-openfeign</artifactId>
|
|
</dependency>
|
|
|
|
<!-- Spring Cloud Alibaba Sentinel -->
|
|
<dependency>
|
|
<groupId>com.alibaba.cloud</groupId>
|
|
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
|
|
</dependency>
|
|
|
|
<!-- MyBatis Plus -->
|
|
<dependency>
|
|
<groupId>com.baomidou</groupId>
|
|
<artifactId>mybatis-plus-boot-starter</artifactId>
|
|
<version>3.5.5</version>
|
|
</dependency>
|
|
|
|
<!-- MySQL Connector -->
|
|
<dependency>
|
|
<groupId>mysql</groupId>
|
|
<artifactId>mysql-connector-java</artifactId>
|
|
<version>8.0.33</version>
|
|
</dependency>
|
|
|
|
<!-- Redis -->
|
|
<dependency>
|
|
<groupId>org.springframework.boot</groupId>
|
|
<artifactId>spring-boot-starter-data-redis</artifactId>
|
|
</dependency>
|
|
|
|
<!-- MinIO -->
|
|
<dependency>
|
|
<groupId>io.minio</groupId>
|
|
<artifactId>minio</artifactId>
|
|
<version>8.5.7</version>
|
|
</dependency>
|
|
|
|
<!-- Hutool工具包 -->
|
|
<dependency>
|
|
<groupId>cn.hutool</groupId>
|
|
<artifactId>hutool-all</artifactId>
|
|
<version>5.8.26</version>
|
|
</dependency>
|
|
|
|
<!-- JWT -->
|
|
<dependency>
|
|
<groupId>io.jsonwebtoken</groupId>
|
|
<artifactId>jjwt-api</artifactId>
|
|
<version>0.12.3</version>
|
|
</dependency>
|
|
<dependency>
|
|
<groupId>io.jsonwebtoken</groupId>
|
|
<artifactId>jjwt-impl</artifactId>
|
|
<version>0.12.3</version>
|
|
<scope>runtime</scope>
|
|
</dependency>
|
|
<dependency>
|
|
<groupId>io.jsonwebtoken</groupId>
|
|
<artifactId>jjwt-jackson</artifactId>
|
|
<version>0.12.3</version>
|
|
<scope>runtime</scope>
|
|
</dependency>
|
|
</dependencies>
|
|
</project>
|
|
```
|
|
|
|
### 3. 创建API网关模块 (video-gateway)
|
|
|
|
1. 右键父工程 -> New -> Module
|
|
2. 选择"Maven",点击"Next"
|
|
3. 填写模块信息:
|
|
- Name: `video-gateway`
|
|
- Parent: `com.nuaa.video:video-platform`
|
|
4. 点击"Finish"
|
|
|
|
5. 修改video-gateway的pom.xml:
|
|
|
|
```xml
|
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
|
<parent>
|
|
<artifactId>video-platform</artifactId>
|
|
<groupId>com.nuaa.video</groupId>
|
|
<version>1.0.0</version>
|
|
</parent>
|
|
<modelVersion>4.0.0</modelVersion>
|
|
|
|
<artifactId>video-gateway</artifactId>
|
|
|
|
<dependencies>
|
|
<!-- Spring Cloud Gateway -->
|
|
<dependency>
|
|
<groupId>org.springframework.cloud</groupId>
|
|
<artifactId>spring-cloud-starter-gateway</artifactId>
|
|
</dependency>
|
|
|
|
<!-- Spring Cloud Alibaba Nacos Discovery -->
|
|
<dependency>
|
|
<groupId>com.alibaba.cloud</groupId>
|
|
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
|
|
</dependency>
|
|
|
|
<!-- Spring Cloud Alibaba Sentinel -->
|
|
<dependency>
|
|
<groupId>com.alibaba.cloud</groupId>
|
|
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
|
|
</dependency>
|
|
|
|
<!-- Sentinel Gateway适配 -->
|
|
<dependency>
|
|
<groupId>com.alibaba.cloud</groupId>
|
|
<artifactId>spring-cloud-alibaba-sentinel-gateway</artifactId>
|
|
</dependency>
|
|
|
|
<!-- Spring Boot Actuator -->
|
|
<dependency>
|
|
<groupId>org.springframework.boot</groupId>
|
|
<artifactId>spring-boot-starter-actuator</artifactId>
|
|
</dependency>
|
|
</dependencies>
|
|
</project>
|
|
```
|
|
|
|
6. 创建application.yml:
|
|
|
|
```yaml
|
|
server:
|
|
port: 9000
|
|
|
|
spring:
|
|
application:
|
|
name: video-gateway
|
|
cloud:
|
|
nacos:
|
|
discovery:
|
|
server-addr: 5.180.253.115:8848
|
|
namespace: public
|
|
group: DEFAULT_GROUP
|
|
gateway:
|
|
discovery:
|
|
locator:
|
|
enabled: true
|
|
lower-case-service-id: true
|
|
routes:
|
|
- id: video-auth
|
|
uri: lb://video-auth
|
|
predicates:
|
|
- Path=/auth/**
|
|
filters:
|
|
- StripPrefix=1
|
|
- id: video-user
|
|
uri: lb://video-user
|
|
predicates:
|
|
- Path=/user/**
|
|
filters:
|
|
- StripPrefix=1
|
|
- id: video-content
|
|
uri: lb://video-content
|
|
predicates:
|
|
- Path=/content/**
|
|
filters:
|
|
- StripPrefix=1
|
|
- id: video-comment
|
|
uri: lb://video-comment
|
|
predicates:
|
|
- Path=/comment/**
|
|
filters:
|
|
- StripPrefix=1
|
|
- id: video-recommend
|
|
uri: lb://video-recommend
|
|
predicates:
|
|
- Path=/recommend/**
|
|
filters:
|
|
- StripPrefix=1
|
|
- id: video-admin
|
|
uri: lb://video-admin
|
|
predicates:
|
|
- Path=/admin/**
|
|
filters:
|
|
- StripPrefix=1
|
|
sentinel:
|
|
transport:
|
|
dashboard: 5.180.253.115:8080
|
|
port: 8719
|
|
eager: true
|
|
scg:
|
|
fallback:
|
|
mode: response
|
|
response-body: '{"code":500,"message":"服务不可用,请稍后再试"}'
|
|
|
|
management:
|
|
endpoints:
|
|
web:
|
|
exposure:
|
|
include: '*'
|
|
```
|
|
|
|
7. 创建主启动类`GatewayApplication.java`:
|
|
|
|
```java
|
|
package com.nuaa.video.gateway;
|
|
|
|
import org.springframework.boot.SpringApplication;
|
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
|
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
|
|
|
@SpringBootApplication
|
|
@EnableDiscoveryClient
|
|
public class GatewayApplication {
|
|
public static void main(String[] args) {
|
|
SpringApplication.run(GatewayApplication.class, args);
|
|
}
|
|
}
|
|
```
|
|
|
|
### 4. 创建认证服务模块 (video-auth)
|
|
|
|
1. 右键父工程 -> New -> Module
|
|
2. 选择"Maven",点击"Next"
|
|
3. 填写模块信息:
|
|
- Name: `video-auth`
|
|
- Parent: `com.nuaa.video:video-platform`
|
|
4. 点击"Finish"
|
|
|
|
5. 修改video-auth的pom.xml:
|
|
|
|
```xml
|
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
|
<parent>
|
|
<artifactId>video-platform</artifactId>
|
|
<groupId>com.nuaa.video</groupId>
|
|
<version>1.0.0</version>
|
|
</parent>
|
|
<modelVersion>4.0.0</modelVersion>
|
|
|
|
<artifactId>video-auth</artifactId>
|
|
|
|
<dependencies>
|
|
<dependency>
|
|
<groupId>com.nuaa.video</groupId>
|
|
<artifactId>video-common</artifactId>
|
|
<version>${project.version}</version>
|
|
</dependency>
|
|
|
|
<!-- Spring Security OAuth2 -->
|
|
<dependency>
|
|
<groupId>org.springframework.boot</groupId>
|
|
<artifactId>spring-boot-starter-oauth2-resource-server</artifactId>
|
|
</dependency>
|
|
|
|
<!-- Spring Security OAuth2 Authorization Server -->
|
|
<dependency>
|
|
<groupId>org.springframework.security</groupId>
|
|
<artifactId>spring-security-oauth2-authorization-server</artifactId>
|
|
<version>1.2.1</version>
|
|
</dependency>
|
|
</dependencies>
|
|
</project>
|
|
```
|
|
|
|
6. 创建application.yml:
|
|
|
|
```yaml
|
|
server:
|
|
port: 9001
|
|
|
|
spring:
|
|
application:
|
|
name: video-auth
|
|
cloud:
|
|
nacos:
|
|
discovery:
|
|
server-addr: 5.180.253.115:8848
|
|
namespace: public
|
|
group: DEFAULT_GROUP
|
|
sentinel:
|
|
transport:
|
|
dashboard: 5.180.253.115:8080
|
|
port: 8720
|
|
eager: true
|
|
datasource:
|
|
url: jdbc:mysql://5.180.253.115:3306/video_auth?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai
|
|
username: root
|
|
password: sty@G458221
|
|
driver-class-name: com.mysql.cj.jdbc.Driver
|
|
data:
|
|
redis:
|
|
host: 5.180.253.115
|
|
port: 6379
|
|
password: redis_EsJ8FX
|
|
database: 0
|
|
|
|
mybatis-plus:
|
|
mapper-locations: classpath:mapper/*.xml
|
|
configuration:
|
|
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
|
|
|
|
jwt:
|
|
secret: video-platform-secret-key-2024-nuaa
|
|
expiration: 86400
|
|
token-header: Authorization
|
|
```
|
|
|
|
7. 创建主启动类`AuthApplication.java`:
|
|
|
|
```java
|
|
package com.nuaa.video.auth;
|
|
|
|
import org.springframework.boot.SpringApplication;
|
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
|
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
|
|
|
@SpringBootApplication
|
|
@EnableDiscoveryClient
|
|
public class AuthApplication {
|
|
public static void main(String[] args) {
|
|
SpringApplication.run(AuthApplication.class, args);
|
|
}
|
|
}
|
|
```
|
|
|
|
### 5. 创建用户服务模块 (video-user)
|
|
|
|
1. 右键父工程 -> New -> Module
|
|
2. 选择"Maven",点击"Next"
|
|
3. 填写模块信息:
|
|
- Name: `video-user`
|
|
- Parent: `com.nuaa.video:video-platform`
|
|
4. 点击"Finish"
|
|
|
|
5. 修改video-user的pom.xml:
|
|
|
|
```xml
|
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
|
<parent>
|
|
<artifactId>video-platform</artifactId>
|
|
<groupId>com.nuaa.video</groupId>
|
|
<version>1.0.0</version>
|
|
</parent>
|
|
<modelVersion>4.0.0</modelVersion>
|
|
|
|
<artifactId>video-user</artifactId>
|
|
|
|
<dependencies>
|
|
<dependency>
|
|
<groupId>com.nuaa.video</groupId>
|
|
<artifactId>video-common</artifactId>
|
|
<version>${project.version}</version>
|
|
</dependency>
|
|
</dependencies>
|
|
</project>
|
|
```
|
|
|
|
6. 创建application.yml:
|
|
|
|
```yaml
|
|
server:
|
|
port: 9002
|
|
|
|
spring:
|
|
application:
|
|
name: video-user
|
|
cloud:
|
|
nacos:
|
|
discovery:
|
|
server-addr: 5.180.253.115:8848
|
|
namespace: public
|
|
group: DEFAULT_GROUP
|
|
sentinel:
|
|
transport:
|
|
dashboard: 5.180.253.115:8080
|
|
port: 8721
|
|
eager: true
|
|
datasource:
|
|
url: jdbc:mysql://5.180.253.115:3306/video_user?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai
|
|
username: root
|
|
password: sty@G458221
|
|
driver-class-name: com.mysql.cj.jdbc.Driver
|
|
data:
|
|
redis:
|
|
host: 5.180.253.115
|
|
port: 6379
|
|
password: redis_EsJ8FX
|
|
database: 1
|
|
|
|
mybatis-plus:
|
|
mapper-locations: classpath:mapper/*.xml
|
|
configuration:
|
|
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
|
|
```
|
|
|
|
7. 创建主启动类`UserApplication.java`:
|
|
|
|
```java
|
|
package com.nuaa.video.user;
|
|
|
|
import org.springframework.boot.SpringApplication;
|
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
|
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
|
|
|
@SpringBootApplication
|
|
@EnableDiscoveryClient
|
|
public class UserApplication {
|
|
public static void main(String[] args) {
|
|
SpringApplication.run(UserApplication.class, args);
|
|
}
|
|
}
|
|
```
|
|
|
|
### 6. 创建内容服务模块 (video-content)
|
|
|
|
1. 右键父工程 -> New -> Module
|
|
2. 选择"Maven",点击"Next"
|
|
3. 填写模块信息:
|
|
- Name: `video-content`
|
|
- Parent: `com.nuaa.video:video-platform`
|
|
4. 点击"Finish"
|
|
|
|
5. 修改video-content的pom.xml:
|
|
|
|
```xml
|
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
|
<parent>
|
|
<artifactId>video-platform</artifactId>
|
|
<groupId>com.nuaa.video</groupId>
|
|
<version>1.0.0</version>
|
|
</parent>
|
|
<modelVersion>4.0.0</modelVersion>
|
|
|
|
<artifactId>video-content</artifactId>
|
|
|
|
<dependencies>
|
|
<dependency>
|
|
<groupId>com.nuaa.video</groupId>
|
|
<artifactId>video-common</artifactId>
|
|
<version>${project.version}</version>
|
|
</dependency>
|
|
|
|
<!-- RocketMQ -->
|
|
<dependency>
|
|
<groupId>org.apache.rocketmq</groupId>
|
|
<artifactId>rocketmq-spring-boot-starter</artifactId>
|
|
<version>2.2.3</version>
|
|
</dependency>
|
|
|
|
<!-- FFmpeg -->
|
|
<dependency>
|
|
<groupId>net.bramp.ffmpeg</groupId>
|
|
<artifactId>ffmpeg</artifactId>
|
|
<version>0.7.0</version>
|
|
</dependency>
|
|
</dependencies>
|
|
</project>
|
|
```
|
|
|
|
6. 创建application.yml:
|
|
|
|
```yaml
|
|
server:
|
|
port: 9003
|
|
|
|
spring:
|
|
application:
|
|
name: video-content
|
|
cloud:
|
|
nacos:
|
|
discovery:
|
|
server-addr: 5.180.253.115:8848
|
|
namespace: public
|
|
group: DEFAULT_GROUP
|
|
sentinel:
|
|
transport:
|
|
dashboard: 5.180.253.115:8080
|
|
port: 8722
|
|
eager: true
|
|
datasource:
|
|
url: jdbc:mysql://5.180.253.115:3306/video_content?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai
|
|
username: root
|
|
password: root
|
|
driver-class-name: com.mysql.cj.jdbc.Driver
|
|
data:
|
|
redis:
|
|
host: 5.180.253.115
|
|
port: 6379
|
|
password: redis_EsJ8FX
|
|
database: 2
|
|
rocketmq:
|
|
name-server: 5.180.253.115:9876
|
|
producer:
|
|
group: video-content-group
|
|
|
|
mybatis-plus:
|
|
mapper-locations: classpath:mapper/*.xml
|
|
configuration:
|
|
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
|
|
|
|
minio:
|
|
endpoint: http://5.180.253.115:9002
|
|
accessKey: minioadmin
|
|
secretKey: minioadmin
|
|
bucketName: video-platform
|
|
```
|
|
|
|
7. 创建主启动类`ContentApplication.java`:
|
|
|
|
```java
|
|
package com.nuaa.video.content;
|
|
|
|
import org.springframework.boot.SpringApplication;
|
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
|
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
|
|
|
@SpringBootApplication
|
|
@EnableDiscoveryClient
|
|
public class ContentApplication {
|
|
public static void main(String[] args) {
|
|
SpringApplication.run(ContentApplication.class, args);
|
|
}
|
|
}
|
|
```
|
|
|
|
### 7. 创建评论服务模块 (video-comment)
|
|
|
|
1. 右键父工程 -> New -> Module
|
|
2. 选择"Maven",点击"Next"
|
|
3. 填写模块信息:
|
|
- Name: `video-comment`
|
|
- Parent: `com.nuaa.video:video-platform`
|
|
4. 点击"Finish"
|
|
|
|
5. 修改video-comment的pom.xml:
|
|
|
|
```xml
|
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
|
<parent>
|
|
<artifactId>video-platform</artifactId>
|
|
<groupId>com.nuaa.video</groupId>
|
|
<version>1.0.0</version>
|
|
</parent>
|
|
<modelVersion>4.0.0</modelVersion>
|
|
|
|
<artifactId>video-comment</artifactId>
|
|
|
|
<dependencies>
|
|
<dependency>
|
|
<groupId>com.nuaa.video</groupId>
|
|
<artifactId>video-common</artifactId>
|
|
<version>${project.version}</version>
|
|
</dependency>
|
|
</dependencies>
|
|
</project>
|
|
```
|
|
|
|
6. 创建application.yml:
|
|
|
|
```yaml
|
|
server:
|
|
port: 9004
|
|
|
|
spring:
|
|
application:
|
|
name: video-comment
|
|
cloud:
|
|
nacos:
|
|
discovery:
|
|
server-addr: 5.180.253.115:8848
|
|
namespace: public
|
|
group: DEFAULT_GROUP
|
|
sentinel:
|
|
transport:
|
|
dashboard: 5.180.253.115:8080
|
|
port: 8723
|
|
eager: true
|
|
datasource:
|
|
url: jdbc:mysql://5.180.253.115:3306/video_comment?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai
|
|
username: root
|
|
password: sty@G458221
|
|
driver-class-name: com.mysql.cj.jdbc.Driver
|
|
data:
|
|
redis:
|
|
host: 5.180.253.115
|
|
port: 6379
|
|
password: redis_EsJ8FX
|
|
database: 3
|
|
|
|
mybatis-plus:
|
|
mapper-locations: classpath:mapper/*.xml
|
|
configuration:
|
|
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
|
|
```
|
|
|
|
7. 创建主启动类`CommentApplication.java`:
|
|
|
|
```java
|
|
package com.nuaa.video.comment;
|
|
|
|
import org.springframework.boot.SpringApplication;
|
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
|
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
|
|
|
@SpringBootApplication
|
|
@EnableDiscoveryClient
|
|
public class CommentApplication {
|
|
public static void main(String[] args) {
|
|
SpringApplication.run(CommentApplication.class, args);
|
|
}
|
|
}
|
|
```
|
|
|
|
### 8. 创建推荐服务模块 (video-recommend)
|
|
|
|
1. 右键父工程 -> New -> Module
|
|
2. 选择"Maven",点击"Next"
|
|
3. 填写模块信息:
|
|
- Name: `video-recommend`
|
|
- Parent: `com.nuaa.video:video-platform`
|
|
4. 点击"Finish"
|
|
|
|
5. 修改video-recommend的pom.xml:
|
|
|
|
```xml
|
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
|
<parent>
|
|
<artifactId>video-platform</artifactId>
|
|
<groupId>com.nuaa.video</groupId>
|
|
<version>1.0.0</version>
|
|
</parent>
|
|
<modelVersion>4.0.0</modelVersion>
|
|
|
|
<artifactId>video-recommend</artifactId>
|
|
|
|
<dependencies>
|
|
<dependency>
|
|
<groupId>com.nuaa.video</groupId>
|
|
<artifactId>video-common</artifactId>
|
|
<version>${project.version}</version>
|
|
</dependency>
|
|
|
|
<!-- 机器学习相关 -->
|
|
<dependency>
|
|
<groupId>org.apache.spark</groupId>
|
|
<artifactId>spark-mllib_2.12</artifactId>
|
|
<version>3.4.1</version>
|
|
</dependency>
|
|
|
|
<!-- 数据计算 -->
|
|
<dependency>
|
|
<groupId>org.apache.commons</groupId>
|
|
<artifactId>commons-math3</artifactId>
|
|
<version>3.6.1</version>
|
|
</dependency>
|
|
</dependencies>
|
|
</project>
|
|
```
|
|
|
|
6. 创建application.yml:
|
|
|
|
```yaml
|
|
server:
|
|
port: 9005
|
|
|
|
spring:
|
|
application:
|
|
name: video-recommend
|
|
cloud:
|
|
nacos:
|
|
discovery:
|
|
server-addr: 5.180.253.115:8848
|
|
namespace: public
|
|
group: DEFAULT_GROUP
|
|
sentinel:
|
|
transport:
|
|
dashboard: 5.180.253.115:8080
|
|
port: 8724
|
|
eager: true
|
|
datasource:
|
|
url: jdbc:mysql://5.180.253.115:3306/video_recommend?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai
|
|
username: root
|
|
password: sty@G458221
|
|
driver-class-name: com.mysql.cj.jdbc.Driver
|
|
data:
|
|
redis:
|
|
host: 5.180.253.115
|
|
port: 6379
|
|
password: redis_EsJ8FX
|
|
database: 4
|
|
|
|
mybatis-plus:
|
|
mapper-locations: classpath:mapper/*.xml
|
|
configuration:
|
|
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
|
|
```
|
|
|
|
7. 创建主启动类`RecommendApplication.java`:
|
|
|
|
```java
|
|
package com.nuaa.video.recommend;
|
|
|
|
import org.springframework.boot.SpringApplication;
|
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
|
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
|
|
|
@SpringBootApplication
|
|
@EnableDiscoveryClient
|
|
public class RecommendApplication {
|
|
public static void main(String[] args) {
|
|
SpringApplication.run(RecommendApplication.class, args);
|
|
}
|
|
}
|
|
```
|
|
|
|
### 9. 创建管理后台模块 (video-admin)
|
|
|
|
1. 右键父工程 -> New -> Module
|
|
2. 选择"Maven",点击"Next"
|
|
3. 填写模块信息:
|
|
- Name: `video-admin`
|
|
- Parent: `com.nuaa.video:video-platform`
|
|
4. 点击"Finish"
|
|
|
|
5. 修改video-admin的pom.xml:
|
|
|
|
```xml
|
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
|
<parent>
|
|
<artifactId>video-platform</artifactId>
|
|
<groupId>com.nuaa.video</groupId>
|
|
<version>1.0.0</version>
|
|
</parent>
|
|
<modelVersion>4.0.0</modelVersion>
|
|
|
|
<artifactId>video-admin</artifactId>
|
|
|
|
<dependencies>
|
|
<dependency>
|
|
<groupId>com.nuaa.video</groupId>
|
|
<artifactId>video-common</artifactId>
|
|
<version>${project.version}</version>
|
|
</dependency>
|
|
</dependencies>
|
|
</project>
|
|
```
|
|
|
|
6. 创建application.yml:
|
|
|
|
```yaml
|
|
server:
|
|
port: 9006
|
|
|
|
spring:
|
|
application:
|
|
name: video-admin
|
|
cloud:
|
|
nacos:
|
|
discovery:
|
|
server-addr: 5.180.253.115:8848
|
|
namespace: public
|
|
group: DEFAULT_GROUP
|
|
sentinel:
|
|
transport:
|
|
dashboard: 5.180.253.115:8080
|
|
port: 8725
|
|
eager: true
|
|
datasource:
|
|
url: jdbc:mysql://5.180.253.115:3306/video_admin?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai
|
|
username: root
|
|
password: sty@G458221
|
|
driver-class-name: com.mysql.cj.jdbc.Driver
|
|
data:
|
|
redis:
|
|
host: 5.180.253.115
|
|
port: 6379
|
|
password: redis_EsJ8FX
|
|
database: 5
|
|
|
|
mybatis-plus:
|
|
mapper-locations: classpath:mapper/*.xml
|
|
configuration:
|
|
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
|
|
```
|
|
|
|
7. 创建主启动类`AdminApplication.java`:
|
|
|
|
```java
|
|
package com.nuaa.video.admin;
|
|
|
|
import org.springframework.boot.SpringApplication;
|
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
|
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
|
|
|
@SpringBootApplication
|
|
@EnableDiscoveryClient
|
|
public class AdminApplication {
|
|
public static void main(String[] args) {
|
|
SpringApplication.run(AdminApplication.class, args);
|
|
}
|
|
}
|
|
```
|
|
|