generated from wenxin/springboot-template
修复mybatis-plus日志,Bot日志不加载到日志文件
This commit is contained in:
parent
dc13b92f04
commit
12e8ddf9f4
10
pom.xml
10
pom.xml
@ -34,6 +34,11 @@
|
|||||||
<artifactId>mirai-core-jvm</artifactId>
|
<artifactId>mirai-core-jvm</artifactId>
|
||||||
<version>2.99.0-local</version>
|
<version>2.99.0-local</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>net.mamoe</groupId>
|
||||||
|
<artifactId>mirai-logging-log4j2</artifactId>
|
||||||
|
<version>2.16.0</version>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.baomidou</groupId>
|
<groupId>com.baomidou</groupId>
|
||||||
<artifactId>mybatis-plus-boot-starter</artifactId>
|
<artifactId>mybatis-plus-boot-starter</artifactId>
|
||||||
@ -79,6 +84,11 @@
|
|||||||
<artifactId>thumbnailator</artifactId>
|
<artifactId>thumbnailator</artifactId>
|
||||||
<version>0.4.20</version>
|
<version>0.4.20</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<!--邮箱-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-mail</artifactId>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
<dependencyManagement>
|
<dependencyManagement>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
@ -3,19 +3,18 @@ package com.linxyun.homework.bot;
|
|||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.linxyun.homework.bot.handler.MyEventHandler;
|
import com.linxyun.homework.bot.handler.MyEventHandler;
|
||||||
import com.linxyun.homework.domain.dto.ClassGroupTeacher;
|
import com.linxyun.homework.domain.dto.ClassGroupTeacher;
|
||||||
import com.linxyun.homework.domain.po.Class;
|
import com.linxyun.homework.domain.po.Class;;
|
||||||
import com.linxyun.homework.domain.po.ClassQqGroupTeacher;
|
|
||||||
import com.linxyun.homework.mapper.ClassMapper;
|
import com.linxyun.homework.mapper.ClassMapper;
|
||||||
import com.linxyun.homework.mapper.ClassQqGroupTeacherMapper;
|
import com.linxyun.homework.mapper.ClassQqGroupTeacherMapper;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import net.mamoe.mirai.Bot;
|
||||||
import net.mamoe.mirai.BotFactory;
|
import net.mamoe.mirai.BotFactory;
|
||||||
import net.mamoe.mirai.auth.BotAuthorization;
|
import net.mamoe.mirai.auth.BotAuthorization;
|
||||||
import net.mamoe.mirai.event.EventChannel;
|
import net.mamoe.mirai.event.EventChannel;
|
||||||
import net.mamoe.mirai.event.events.BotEvent;
|
import net.mamoe.mirai.event.events.BotEvent;
|
||||||
import net.mamoe.mirai.event.events.GroupMessageEvent;
|
import net.mamoe.mirai.event.events.GroupMessageEvent;
|
||||||
import net.mamoe.mirai.utils.BotConfiguration;
|
import net.mamoe.mirai.utils.BotConfiguration;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.boot.ApplicationArguments;
|
import org.springframework.boot.ApplicationArguments;
|
||||||
import org.springframework.boot.ApplicationRunner;
|
import org.springframework.boot.ApplicationRunner;
|
||||||
@ -70,7 +69,7 @@ public class MyBot implements ApplicationRunner {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void runBot() {
|
public void runBot() {
|
||||||
net.mamoe.mirai.Bot bot = BotFactory.INSTANCE.newBot(qq, BotAuthorization.byQRCode(), configuration -> {
|
Bot bot = BotFactory.INSTANCE.newBot(qq, BotAuthorization.byQRCode(), configuration -> {
|
||||||
configuration.setProtocol(BotConfiguration.MiraiProtocol.MACOS);
|
configuration.setProtocol(BotConfiguration.MiraiProtocol.MACOS);
|
||||||
// 指定设备信息文件路径,文件不存在将自动生成一个默认的,存在就读取
|
// 指定设备信息文件路径,文件不存在将自动生成一个默认的,存在就读取
|
||||||
configuration.fileBasedDeviceInfo("deviceInfo_" + qq + ".json");
|
configuration.fileBasedDeviceInfo("deviceInfo_" + qq + ".json");
|
||||||
|
@ -0,0 +1,24 @@
|
|||||||
|
package com.linxyun.homework.common.exception;
|
||||||
|
|
||||||
|
import com.linxyun.homework.utils.EmailUtils;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.web.bind.annotation.ControllerAdvice;
|
||||||
|
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||||
|
import org.springframework.web.bind.annotation.ResponseBody;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@ControllerAdvice
|
||||||
|
public class GlobalExceptionHandler {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private EmailUtils emailUtils;
|
||||||
|
|
||||||
|
@ExceptionHandler(value = Exception.class)
|
||||||
|
@ResponseBody
|
||||||
|
public void exceptionHandler(Exception e) {
|
||||||
|
emailUtils.sendEmail("异常捕获", e.getMessage());
|
||||||
|
log.error("ExceptionHandler exception: {}", e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
30
src/main/java/com/linxyun/homework/utils/EmailUtils.java
Normal file
30
src/main/java/com/linxyun/homework/utils/EmailUtils.java
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
package com.linxyun.homework.utils;
|
||||||
|
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.mail.SimpleMailMessage;
|
||||||
|
import org.springframework.mail.javamail.JavaMailSender;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@Component
|
||||||
|
public class EmailUtils {
|
||||||
|
@Resource
|
||||||
|
private JavaMailSender javaMailSender;
|
||||||
|
|
||||||
|
@Value("${spring.mail.to-address}")
|
||||||
|
private String toAddress;
|
||||||
|
|
||||||
|
public void sendEmail(String subject, String text) {
|
||||||
|
SimpleMailMessage simpleMailMessage = new SimpleMailMessage();
|
||||||
|
simpleMailMessage.setFrom("wenxin_web@163.com");
|
||||||
|
simpleMailMessage.setTo(toAddress);
|
||||||
|
simpleMailMessage.setSubject(subject);
|
||||||
|
simpleMailMessage.setText(text);
|
||||||
|
CompletableFuture.runAsync(() -> javaMailSender.send(simpleMailMessage));
|
||||||
|
}
|
||||||
|
}
|
@ -16,6 +16,14 @@ spring: #springboot的配置
|
|||||||
# 使用druid数据源
|
# 使用druid数据源
|
||||||
type: com.alibaba.druid.pool.DruidDataSource
|
type: com.alibaba.druid.pool.DruidDataSource
|
||||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||||
|
mail:
|
||||||
|
host: smtp.163.com
|
||||||
|
port: 465
|
||||||
|
protocol: smtps
|
||||||
|
username: wenxin_web@163.com
|
||||||
|
password: YCOUPMDBKDTQRAJR
|
||||||
|
default-encoding: UTF-8
|
||||||
|
to-address: 1731551615@qq.com
|
||||||
|
|
||||||
# mybatis-plus相关配置
|
# mybatis-plus相关配置
|
||||||
mybatis-plus:
|
mybatis-plus:
|
||||||
@ -36,19 +44,20 @@ mybatis-plus:
|
|||||||
# 如果查询结果中包含空值的列,则 MyBatis 在映射的时候,不会映射这个字段
|
# 如果查询结果中包含空值的列,则 MyBatis 在映射的时候,不会映射这个字段
|
||||||
call-setters-on-nulls: true
|
call-setters-on-nulls: true
|
||||||
# 这个配置会将执行的sql打印出来,在开发或测试的时候可以用
|
# 这个配置会将执行的sql打印出来,在开发或测试的时候可以用
|
||||||
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
|
log-impl: org.apache.ibatis.logging.slf4j.Slf4jImpl
|
||||||
|
|
||||||
|
|
||||||
logging:
|
logging:
|
||||||
file:
|
file:
|
||||||
# 输出的log文件名
|
# 输出的log文件名
|
||||||
name: slf4j-test
|
name: application.log
|
||||||
# 输出的文件的路径
|
# 输出的文件的路径
|
||||||
path: ./logs
|
path: ./logs
|
||||||
level:
|
level:
|
||||||
# 输出级别
|
# 输出级别
|
||||||
root: debug
|
root: info
|
||||||
# 特定的mapper下的输出级别
|
# 特定的mapper下的输出级别
|
||||||
com.example.demo.mapper: debug
|
com.linxyun.homework.mapper: debug # 设置 MyBatis-Plus 日志级别为 DEBUG
|
||||||
# xml配置文件
|
# xml配置文件
|
||||||
config: classpath:logback.xml
|
config: classpath:logback.xml
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user