模块初始化
This commit is contained in:
Vendored
+4
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"java.compile.nullAnalysis.mode": "automatic",
|
||||
"java.configuration.updateBuildConfiguration": "automatic"
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
/mvnw text eol=lf
|
||||
*.cmd text eol=crlf
|
||||
@@ -0,0 +1,33 @@
|
||||
HELP.md
|
||||
target/
|
||||
.mvn/wrapper/maven-wrapper.jar
|
||||
!**/src/main/**/target/
|
||||
!**/src/test/**/target/
|
||||
|
||||
### STS ###
|
||||
.apt_generated
|
||||
.classpath
|
||||
.factorypath
|
||||
.project
|
||||
.settings
|
||||
.springBeans
|
||||
.sts4-cache
|
||||
|
||||
### IntelliJ IDEA ###
|
||||
.idea
|
||||
*.iws
|
||||
*.iml
|
||||
*.ipr
|
||||
|
||||
### NetBeans ###
|
||||
/nbproject/private/
|
||||
/nbbuild/
|
||||
/dist/
|
||||
/nbdist/
|
||||
/.nb-gradle/
|
||||
build/
|
||||
!**/src/main/**/build/
|
||||
!**/src/test/**/build/
|
||||
|
||||
### VS Code ###
|
||||
.vscode/
|
||||
@@ -0,0 +1,3 @@
|
||||
wrapperVersion=3.3.4
|
||||
distributionType=only-script
|
||||
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.12/apache-maven-3.9.12-bin.zip
|
||||
@@ -0,0 +1,140 @@
|
||||
<?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>2.7.18</version>
|
||||
<relativePath/>
|
||||
</parent>
|
||||
|
||||
<groupId>com.xiaowang</groupId>
|
||||
<artifactId>MessageHub</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<name>MessageHub</name>
|
||||
<description>MessageHub - 消息中心微服务,提供消息队列、数据库操作等服务</description>
|
||||
|
||||
<url/>
|
||||
<licenses>
|
||||
<license/>
|
||||
</licenses>
|
||||
<developers>
|
||||
<developer/>
|
||||
</developers>
|
||||
<scm>
|
||||
<connection/>
|
||||
<developerConnection/>
|
||||
<tag/>
|
||||
<url/>
|
||||
</scm>
|
||||
|
||||
<properties>
|
||||
<java.version>17</java.version>
|
||||
<spring-cloud.version>2021.0.8</spring-cloud.version>
|
||||
<spring-cloud-alibaba.version>2021.0.5.0</spring-cloud-alibaba.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-logging</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-log4j2</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-amqp</artifactId>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-logging</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-bootstrap</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-jdbc</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.mysql</groupId>
|
||||
<artifactId>mysql-connector-j</artifactId>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-boot-starter</artifactId>
|
||||
<version>3.5.3.1</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>druid-spring-boot-starter</artifactId>
|
||||
<version>1.2.23</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-dependencies</artifactId>
|
||||
<version>${spring-cloud.version}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
<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>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.xiaowang.messagehub;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class MessageHubApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(MessageHubApplication.class, args);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.xiaowang.messagehub.config;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.DbType;
|
||||
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
|
||||
import com.baomidou.mybatisplus.extension.plugins.inner.BlockAttackInnerInterceptor;
|
||||
import com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor;
|
||||
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
@MapperScan("com.xiaowang.messagehub.mapper")
|
||||
public class MyBatisPlusConfig {
|
||||
|
||||
@Bean
|
||||
public MybatisPlusInterceptor mybatisPlusInterceptor() {
|
||||
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
|
||||
|
||||
interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
|
||||
|
||||
interceptor.addInnerInterceptor(new OptimisticLockerInnerInterceptor());
|
||||
|
||||
interceptor.addInnerInterceptor(new BlockAttackInnerInterceptor());
|
||||
|
||||
return interceptor;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.xiaowang.messagehub.config;
|
||||
|
||||
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
|
||||
import org.apache.ibatis.reflection.MetaObject;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Component
|
||||
public class MyMetaObjectHandler implements MetaObjectHandler {
|
||||
|
||||
@Override
|
||||
public void insertFill(MetaObject metaObject) {
|
||||
this.strictInsertFill(metaObject, "createTime", LocalDateTime.class, LocalDateTime.now());
|
||||
this.strictInsertFill(metaObject, "updateTime", LocalDateTime.class, LocalDateTime.now());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateFill(MetaObject metaObject) {
|
||||
this.strictUpdateFill(metaObject, "updateTime", LocalDateTime.class, LocalDateTime.now());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package com.xiaowang.messagehub.config;
|
||||
|
||||
import org.springframework.amqp.core.*;
|
||||
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
|
||||
import org.springframework.amqp.support.converter.MessageConverter;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
public class RabbitMQConfig {
|
||||
|
||||
public static final String MESSAGE_QUEUE = "message.queue";
|
||||
public static final String MESSAGE_EXCHANGE = "message.exchange";
|
||||
public static final String MESSAGE_ROUTING_KEY = "message.routing.key";
|
||||
|
||||
@Bean
|
||||
public Queue messageQueue() {
|
||||
return QueueBuilder.durable(MESSAGE_QUEUE).build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public TopicExchange messageExchange() {
|
||||
return new TopicExchange(MESSAGE_EXCHANGE, true, false);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Binding messageBinding() {
|
||||
return BindingBuilder.bind(messageQueue())
|
||||
.to(messageExchange())
|
||||
.with(MESSAGE_ROUTING_KEY);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public MessageConverter jsonMessageConverter() {
|
||||
return new Jackson2JsonMessageConverter();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public RabbitTemplate rabbitTemplate(ConnectionFactory connectionFactory) {
|
||||
RabbitTemplate rabbitTemplate = new RabbitTemplate(connectionFactory);
|
||||
rabbitTemplate.setMessageConverter(jsonMessageConverter());
|
||||
return rabbitTemplate;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
package com.xiaowang.messagehub.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@TableName("message")
|
||||
public class Message {
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
@TableField("content")
|
||||
private String content;
|
||||
|
||||
@TableField("topic")
|
||||
private String topic;
|
||||
|
||||
@TableField("status")
|
||||
private Integer status;
|
||||
|
||||
@TableField(value = "create_time", fill = FieldFill.INSERT)
|
||||
private LocalDateTime createTime;
|
||||
|
||||
@TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE)
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
@TableLogic
|
||||
@TableField("deleted")
|
||||
private Integer deleted;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getContent() {
|
||||
return content;
|
||||
}
|
||||
|
||||
public void setContent(String content) {
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
public String getTopic() {
|
||||
return topic;
|
||||
}
|
||||
|
||||
public void setTopic(String topic) {
|
||||
this.topic = topic;
|
||||
}
|
||||
|
||||
public Integer getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(Integer status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public LocalDateTime getCreateTime() {
|
||||
return createTime;
|
||||
}
|
||||
|
||||
public void setCreateTime(LocalDateTime createTime) {
|
||||
this.createTime = createTime;
|
||||
}
|
||||
|
||||
public LocalDateTime getUpdateTime() {
|
||||
return updateTime;
|
||||
}
|
||||
|
||||
public void setUpdateTime(LocalDateTime updateTime) {
|
||||
this.updateTime = updateTime;
|
||||
}
|
||||
|
||||
public Integer getDeleted() {
|
||||
return deleted;
|
||||
}
|
||||
|
||||
public void setDeleted(Integer deleted) {
|
||||
this.deleted = deleted;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
package com.xiaowang.messagehub.health;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.SQLException;
|
||||
|
||||
@Component
|
||||
public class ConnectionHealthChecker {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(ConnectionHealthChecker.class);
|
||||
|
||||
@Autowired
|
||||
private ConnectionFactory rabbitMQConnectionFactory;
|
||||
|
||||
private String mysqlUrl;
|
||||
private String mysqlUsername;
|
||||
private String mysqlPassword;
|
||||
private String nacosServerAddr;
|
||||
|
||||
@Autowired
|
||||
public void setMysqlConfig(org.springframework.core.env.Environment env) {
|
||||
this.mysqlUrl = env.getProperty("spring.datasource.url");
|
||||
this.mysqlUsername = env.getProperty("spring.datasource.username");
|
||||
this.mysqlPassword = env.getProperty("spring.datasource.password");
|
||||
this.nacosServerAddr = env.getProperty("spring.cloud.nacos.discovery.server-addr");
|
||||
}
|
||||
|
||||
public boolean checkMySQL() {
|
||||
logger.info("开始检查MySQL连接...");
|
||||
try (java.sql.Connection conn = DriverManager.getConnection(mysqlUrl, mysqlUsername, mysqlPassword)) {
|
||||
if (conn.isValid(5)) {
|
||||
logger.info("MySQL连接成功 - URL: {}", mysqlUrl);
|
||||
return true;
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
logger.error("MySQL连接失败 - URL: {}, 错误: {}", mysqlUrl, e.getMessage(), e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean checkRabbitMQ() {
|
||||
logger.info("开始检查RabbitMQ连接...");
|
||||
try {
|
||||
org.springframework.amqp.rabbit.connection.Connection connection = rabbitMQConnectionFactory.createConnection();
|
||||
if (connection.isOpen()) {
|
||||
logger.info("RabbitMQ连接成功 - Host: {}, Port: {}",
|
||||
rabbitMQConnectionFactory.getHost(), rabbitMQConnectionFactory.getPort());
|
||||
connection.close();
|
||||
return true;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error("RabbitMQ连接失败 - Host: {}, Port: {}, 错误: {}",
|
||||
rabbitMQConnectionFactory.getHost(), rabbitMQConnectionFactory.getPort(), e.getMessage(), e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean checkNacos() {
|
||||
logger.info("开始检查Nacos连接...");
|
||||
logger.info("Nacos配置 - ServerAddr: {}, Namespace: MessageHub", nacosServerAddr);
|
||||
logger.info("Nacos连接检查完成(Nacos客户端会在启动时自动连接)");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
+64
@@ -0,0 +1,64 @@
|
||||
package com.xiaowang.messagehub.listener;
|
||||
|
||||
import com.xiaowang.messagehub.health.ConnectionHealthChecker;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.context.event.ApplicationReadyEvent;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class ApplicationStartupListener implements ApplicationListener<ApplicationReadyEvent> {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(ApplicationStartupListener.class);
|
||||
|
||||
@Autowired
|
||||
private ConnectionHealthChecker connectionHealthChecker;
|
||||
|
||||
@Override
|
||||
public void onApplicationEvent(ApplicationReadyEvent event) {
|
||||
logger.info("========================================");
|
||||
logger.info("MessageHub服务启动完成,开始检查各组件连接状态...");
|
||||
logger.info("========================================");
|
||||
|
||||
boolean allSuccess = true;
|
||||
|
||||
logger.info("");
|
||||
logger.info("【1/3】检查MySQL连接...");
|
||||
if (connectionHealthChecker.checkMySQL()) {
|
||||
logger.info("✓ MySQL连接检查通过");
|
||||
} else {
|
||||
logger.error("✗ MySQL连接检查失败");
|
||||
allSuccess = false;
|
||||
}
|
||||
|
||||
logger.info("");
|
||||
logger.info("【2/3】检查RabbitMQ连接...");
|
||||
if (connectionHealthChecker.checkRabbitMQ()) {
|
||||
logger.info("✓ RabbitMQ连接检查通过");
|
||||
} else {
|
||||
logger.error("✗ RabbitMQ连接检查失败");
|
||||
allSuccess = false;
|
||||
}
|
||||
|
||||
logger.info("");
|
||||
logger.info("【3/3】检查Nacos连接...");
|
||||
if (connectionHealthChecker.checkNacos()) {
|
||||
logger.info("✓ Nacos连接检查通过");
|
||||
} else {
|
||||
logger.error("✗ Nacos连接检查失败");
|
||||
allSuccess = false;
|
||||
}
|
||||
|
||||
logger.info("");
|
||||
logger.info("========================================");
|
||||
if (allSuccess) {
|
||||
logger.info("所有组件连接检查完成,状态:全部成功");
|
||||
logger.info("MessageHub服务已就绪,可以正常使用");
|
||||
} else {
|
||||
logger.error("部分组件连接检查失败,请检查日志并确认配置");
|
||||
}
|
||||
logger.info("========================================");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package com.xiaowang.messagehub.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.xiaowang.messagehub.entity.Message;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface MessageMapper extends BaseMapper<Message> {
|
||||
}
|
||||
|
||||
@@ -0,0 +1,188 @@
|
||||
# Spring Boot应用配置文件
|
||||
# 用于配置MessageHub微服务的各种组件连接参数
|
||||
|
||||
spring:
|
||||
# 应用名称配置
|
||||
application:
|
||||
name: MessageHub
|
||||
|
||||
# 数据库初始化配置
|
||||
sql:
|
||||
init:
|
||||
# 禁用数据库初始化检测,解决MyBatis-Plus与Spring Boot 3.x兼容性问题
|
||||
mode: never
|
||||
|
||||
# Spring Cloud配置
|
||||
cloud:
|
||||
# Nacos服务发现与注册中心配置
|
||||
nacos:
|
||||
discovery:
|
||||
# Nacos集群地址,多个地址用逗号分隔
|
||||
server-addr: 192.168.5.101:8848,192.168.5.102:8848,192.168.5.103:8848
|
||||
# 命名空间ID,用于环境隔离
|
||||
namespace: MessageHub
|
||||
# 分组名称,默认为DEFAULT_GROUP
|
||||
group: DEFAULT_GROUP
|
||||
# 服务名称,使用应用名称
|
||||
service: ${spring.application.name}
|
||||
# 是否启用服务发现
|
||||
enabled: true
|
||||
# 是否启用服务注册
|
||||
register-enabled: true
|
||||
# Nacos认证用户名
|
||||
username: xiaowang
|
||||
# Nacos认证密码
|
||||
password: 122503wcy....
|
||||
config:
|
||||
# Nacos配置中心集群地址
|
||||
server-addr: 192.168.5.101:8848,192.168.5.102:8848,192.168.5.103:8848
|
||||
# 配置中心命名空间
|
||||
namespace: MessageHub
|
||||
# 配置分组
|
||||
group: DEFAULT_GROUP
|
||||
# 配置文件名称
|
||||
name: MessageHub
|
||||
# 配置文件扩展名
|
||||
file-extension: yaml
|
||||
# 是否启用配置中心
|
||||
enabled: true
|
||||
# Nacos认证用户名
|
||||
username: xiaowang
|
||||
# Nacos认证密码
|
||||
password: 122503wcy....
|
||||
|
||||
# RabbitMQ消息队列配置
|
||||
rabbitmq:
|
||||
# RabbitMQ服务器地址
|
||||
host: 192.168.5.15
|
||||
# RabbitMQ服务端口
|
||||
port: 5672
|
||||
# RabbitMQ用户名
|
||||
username: rabbitmq
|
||||
# RabbitMQ密码
|
||||
password: 122503wcy....
|
||||
# 虚拟主机,默认为/
|
||||
virtual-host: /
|
||||
# 消息监听器配置
|
||||
listener:
|
||||
simple:
|
||||
# 消息确认模式:auto-自动确认,manual-手动确认,none-不确认
|
||||
acknowledge-mode: auto
|
||||
# 预取消息数量,设置为1表示公平分发
|
||||
prefetch: 1
|
||||
|
||||
# 数据源配置
|
||||
datasource:
|
||||
# 数据源类型,使用Druid连接池
|
||||
type: com.alibaba.druid.pool.DruidDataSource
|
||||
# JDBC驱动类名
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
# 数据库连接URL
|
||||
# useUnicode=true: 使用Unicode字符集
|
||||
# characterEncoding=utf8: 字符编码为UTF-8
|
||||
# useSSL=false: 不使用SSL连接
|
||||
# serverTimezone=Asia/Shanghai: 服务器时区为上海
|
||||
# allowPublicKeyRetrieval=true: 允许获取公钥(解决MySQL 8.0连接问题)
|
||||
url: jdbc:mysql://192.168.5.15:3306/messagehub?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true
|
||||
# 数据库用户名
|
||||
username: root
|
||||
# 数据库密码
|
||||
password: 122503wcy
|
||||
# Druid连接池配置
|
||||
druid:
|
||||
# 初始化连接数,系统启动时创建的连接数量
|
||||
initial-size: 5
|
||||
# 最小空闲连接数,连接池中最少保持的空闲连接数
|
||||
min-idle: 5
|
||||
# 最大活跃连接数,连接池中最多同时活跃的连接数
|
||||
max-active: 20
|
||||
# 获取连接等待超时时间(毫秒),超过此时间未获取到连接则抛出异常
|
||||
max-wait: 60000
|
||||
# 配置间隔多久进行一次检测,检测需要关闭的空闲连接(毫秒)
|
||||
time-between-eviction-runs-millis: 60000
|
||||
# 配置连接在池中最小生存的时间(毫秒),超过此时间则被回收
|
||||
min-evictable-idle-time-millis: 300000
|
||||
# 验证连接是否有效的SQL语句,MySQL推荐使用SELECT 1
|
||||
validation-query: SELECT 1
|
||||
# 申请连接时执行validationQuery检测连接是否有效
|
||||
test-while-idle: true
|
||||
# 申请连接时执行validationQuery检测连接是否有效,影响性能
|
||||
test-on-borrow: false
|
||||
# 归还连接时执行validationQuery检测连接是否有效,影响性能
|
||||
test-on-return: false
|
||||
# 是否缓存preparedStatement,即PSCache,PSCache对支持游标的数据库性能提升巨大
|
||||
pool-prepared-statements: true
|
||||
# 每个连接上PSCache的大小
|
||||
max-pool-prepared-statement-per-connection-size: 20
|
||||
# 配置监控统计拦截的filters,stat:监控统计,wall:防火墙,slf4j:日志
|
||||
filters: stat,wall,slf4j
|
||||
# 通过connectProperties属性来打开mergeSql功能,慢SQL记录
|
||||
connection-properties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000
|
||||
# 合并多个DruidDataSource的监控数据
|
||||
use-global-data-source-stat: true
|
||||
# Druid监控页面配置
|
||||
stat-view-servlet:
|
||||
# 是否启用Druid监控页面
|
||||
enabled: true
|
||||
# 访问监控页面的URL路径
|
||||
url-pattern: /druid/*
|
||||
# 重置功能开关
|
||||
reset-enable: false
|
||||
# 登录监控页面的用户名
|
||||
login-username: admin
|
||||
# 登录监控页面的密码
|
||||
login-password: admin
|
||||
# 允许访问的IP地址,为空表示允许所有
|
||||
allow: ""
|
||||
# 拒绝访问的IP地址
|
||||
deny: ""
|
||||
# WebStatFilter配置,用于采集web-jdbc关联监控的数据
|
||||
web-stat-filter:
|
||||
# 是否启用WebStatFilter
|
||||
enabled: true
|
||||
# 拦截所有请求
|
||||
url-pattern: /*
|
||||
# 排除静态资源文件
|
||||
exclusions: "*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*"
|
||||
# 开启session统计功能
|
||||
session-stat-enable: true
|
||||
# session统计的最大数量,默认100
|
||||
session-stat-max-count: 1000
|
||||
|
||||
# MyBatis-Plus配置
|
||||
mybatis-plus:
|
||||
# Mapper XML文件位置,用于存放自定义SQL
|
||||
mapper-locations: classpath:mapper/*.xml
|
||||
# 实体类包路径,用于配置类型别名
|
||||
type-aliases-package: com.xiaowang.messagehub.entity
|
||||
# MyBatis核心配置
|
||||
configuration:
|
||||
# 开启驼峰命名转换,数据库字段user_name自动映射为userName
|
||||
map-underscore-to-camel-case: true
|
||||
# 使用Log4j2作为日志实现
|
||||
log-impl: org.apache.ibatis.logging.log4j2.Log4j2Impl
|
||||
# MyBatis-Plus全局配置
|
||||
global-config:
|
||||
# 数据库配置
|
||||
db-config:
|
||||
# 主键类型:auto-数据库自增,input-手动输入,assign_id-雪花算法,assign_uuid-UUID
|
||||
id-type: auto
|
||||
# 逻辑删除字段名
|
||||
logic-delete-field: deleted
|
||||
# 逻辑删除值(已删除)
|
||||
logic-delete-value: 1
|
||||
# 逻辑未删除值(未删除)
|
||||
logic-not-delete-value: 0
|
||||
|
||||
# 日志配置
|
||||
logging:
|
||||
# 日志配置文件路径
|
||||
config: classpath:log4j2.xml
|
||||
# 日志文件存储路径
|
||||
file:
|
||||
path: ./logs
|
||||
|
||||
# 服务器配置
|
||||
server:
|
||||
# 服务端口号
|
||||
port: 8080
|
||||
@@ -0,0 +1,62 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Configuration status="WARN">
|
||||
<Properties>
|
||||
<Property name="LOG_PATTERN">%d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n</Property>
|
||||
<Property name="LOG_HOME">${sys:logging.file.path:-./logs}</Property>
|
||||
</Properties>
|
||||
|
||||
<Appenders>
|
||||
<Console name="Console" target="SYSTEM_OUT">
|
||||
<PatternLayout pattern="${LOG_PATTERN}"/>
|
||||
</Console>
|
||||
|
||||
<RollingFile name="RollingFile" fileName="${LOG_HOME}/messagehub.log"
|
||||
filePattern="${LOG_HOME}/messagehub-%d{yyyy-MM-dd}-%i.log.gz">
|
||||
<PatternLayout pattern="${LOG_PATTERN}"/>
|
||||
<Policies>
|
||||
<TimeBasedTriggeringPolicy interval="1" modulate="true"/>
|
||||
<SizeBasedTriggeringPolicy size="100 MB"/>
|
||||
</Policies>
|
||||
<DefaultRolloverStrategy max="30">
|
||||
<Delete basePath="${LOG_HOME}" maxDepth="1">
|
||||
<IfFileName glob="messagehub-*.log.gz"/>
|
||||
<IfLastModified age="30d"/>
|
||||
</Delete>
|
||||
</DefaultRolloverStrategy>
|
||||
</RollingFile>
|
||||
|
||||
<RollingFile name="ErrorRollingFile" fileName="${LOG_HOME}/messagehub-error.log"
|
||||
filePattern="${LOG_HOME}/messagehub-error-%d{yyyy-MM-dd}-%i.log.gz">
|
||||
<PatternLayout pattern="${LOG_PATTERN}"/>
|
||||
<ThresholdFilter level="ERROR" onMatch="ACCEPT" onMismatch="DENY"/>
|
||||
<Policies>
|
||||
<TimeBasedTriggeringPolicy interval="1" modulate="true"/>
|
||||
<SizeBasedTriggeringPolicy size="100 MB"/>
|
||||
</Policies>
|
||||
<DefaultRolloverStrategy max="30">
|
||||
<Delete basePath="${LOG_HOME}" maxDepth="1">
|
||||
<IfFileName glob="messagehub-error-*.log.gz"/>
|
||||
<IfLastModified age="30d"/>
|
||||
</Delete>
|
||||
</DefaultRolloverStrategy>
|
||||
</RollingFile>
|
||||
</Appenders>
|
||||
|
||||
<Loggers>
|
||||
<Root level="INFO">
|
||||
<AppenderRef ref="Console"/>
|
||||
<AppenderRef ref="RollingFile"/>
|
||||
<AppenderRef ref="ErrorRollingFile"/>
|
||||
</Root>
|
||||
|
||||
<Logger name="com.xiaowang.messagehub" level="DEBUG" additivity="false">
|
||||
<AppenderRef ref="Console"/>
|
||||
<AppenderRef ref="RollingFile"/>
|
||||
<AppenderRef ref="ErrorRollingFile"/>
|
||||
</Logger>
|
||||
|
||||
<Logger name="org.springframework" level="INFO"/>
|
||||
<Logger name="com.alibaba.nacos" level="INFO"/>
|
||||
<Logger name="org.mybatis" level="DEBUG"/>
|
||||
</Loggers>
|
||||
</Configuration>
|
||||
@@ -0,0 +1,16 @@
|
||||
CREATE DATABASE IF NOT EXISTS messagehub DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||
|
||||
USE messagehub;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS message (
|
||||
id BIGINT AUTO_INCREMENT PRIMARY KEY COMMENT '主键ID',
|
||||
content TEXT NOT NULL COMMENT '消息内容',
|
||||
topic VARCHAR(255) NOT NULL COMMENT '消息主题',
|
||||
status TINYINT DEFAULT 0 COMMENT '消息状态:0-未处理,1-已处理,2-处理失败',
|
||||
create_time DATETIME DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
update_time DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||
deleted TINYINT DEFAULT 0 COMMENT '逻辑删除:0-未删除,1-已删除',
|
||||
INDEX idx_topic (topic),
|
||||
INDEX idx_status (status),
|
||||
INDEX idx_create_time (create_time)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='消息表';
|
||||
Reference in New Issue
Block a user