Phase 1 #17: Spring Cloud Alibaba 微服务框架搭建

- Maven 父工程 wm-parent (Spring Boot 3.3.5 + Cloud 2023.0.3 + Alibaba 2023.0.1)
- 12个子模块: wm-common/gateway/base/iot/data-engine/bpm/production/revenue/patrol/bi/notify/job
- wm-common: 统一响应 R<T> + 全局异常处理 + BusinessException
- wm-gateway: Spring Cloud Gateway 路由配置(7个微服务路由)
- 集成: Nacos(注册/配置) + PostgreSQL + Redis + Kafka + Sa-Token + MyBatis-Plus + Knife4j
- docker-compose.yml: 一键启动10个中间件(PG+PostGIS/TDengine/Redis/Kafka/EMQX/Nacos/ES/Kibana/MinIO/GeoServer)
This commit is contained in:
bot_pm
2026-06-14 13:14:07 +08:00
parent 57e4898e87
commit e929f65948
39 changed files with 933 additions and 0 deletions
+15
View File
@@ -0,0 +1,15 @@
<?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>com.water</groupId><artifactId>wm-parent</artifactId><version>1.0.0-SNAPSHOT</version></parent>
<artifactId>wm-common</artifactId>
<dependencies>
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency>
<dependency><groupId>com.baomidou</groupId><artifactId>mybatis-plus-spring-boot3-starter</artifactId></dependency>
<dependency><groupId>com.github.xiaoymin</groupId><artifactId>knife4j-openapi3-jakarta-spring-boot-starter</artifactId></dependency>
<dependency><groupId>cn.hutool</groupId><artifactId>hutool-all</artifactId></dependency>
<dependency><groupId>com.alibaba</groupId><artifactId>easyexcel</artifactId></dependency>
</dependencies>
</project>
@@ -0,0 +1,10 @@
package com.water.common.core.exception;
import lombok.Getter;
@Getter
public class BusinessException extends RuntimeException {
private final int code;
public BusinessException(int code, String message) { super(message); this.code = code; }
public BusinessException(String message) { this(400, message); }
}
@@ -0,0 +1,24 @@
package com.water.common.core.exception;
import com.water.common.core.result.R;
import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {
@ExceptionHandler(BusinessException.class)
public R<Void> handleBusiness(BusinessException e, HttpServletRequest request) {
log.warn("Business exception: {} - {}", e.getCode(), e.getMessage());
return R.fail(e.getCode(), e.getMessage());
}
@ExceptionHandler(Exception.class)
public R<Void> handleException(Exception e, HttpServletRequest request) {
log.error("System exception: {}", e.getMessage(), e);
return R.fail(500, "系统内部错误");
}
}
@@ -0,0 +1,36 @@
package com.water.common.core.result;
import lombok.Data;
import java.io.Serializable;
@Data
public class R<T> implements Serializable {
private int code;
private String message;
private T data;
private long timestamp = System.currentTimeMillis();
public static <T> R<T> ok() {
return ok(null);
}
public static <T> R<T> ok(T data) {
R<T> r = new R<>();
r.code = 200;
r.message = "success";
r.data = data;
return r;
}
public static <T> R<T> fail(int code, String message) {
R<T> r = new R<>();
r.code = code;
r.message = message;
return r;
}
public static <T> R<T> fail(String message) {
return fail(500, message);
}
}