升级SpringBoot 2.3.0
This commit is contained in:
@@ -29,14 +29,14 @@
|
||||
<groupId>com.aliyun.oss</groupId>
|
||||
<artifactId>aliyun-sdk-oss</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.logstash.logback</groupId>
|
||||
<artifactId>logstash-logback-encoder</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.minio</groupId>
|
||||
<artifactId>minio</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>jakarta.validation</groupId>
|
||||
<artifactId>jakarta.validation-api</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<plugins>
|
||||
|
||||
@@ -1,144 +0,0 @@
|
||||
package com.macro.mall.bo;
|
||||
|
||||
/**
|
||||
* Controller层的日志封装类
|
||||
* Created by macro on 2018/4/26.
|
||||
*/
|
||||
public class WebLog {
|
||||
/**
|
||||
* 操作描述
|
||||
*/
|
||||
private String description;
|
||||
|
||||
/**
|
||||
* 操作用户
|
||||
*/
|
||||
private String username;
|
||||
|
||||
/**
|
||||
* 操作时间
|
||||
*/
|
||||
private Long startTime;
|
||||
|
||||
/**
|
||||
* 消耗时间
|
||||
*/
|
||||
private Integer spendTime;
|
||||
|
||||
/**
|
||||
* 根路径
|
||||
*/
|
||||
private String basePath;
|
||||
|
||||
/**
|
||||
* URI
|
||||
*/
|
||||
private String uri;
|
||||
|
||||
/**
|
||||
* URL
|
||||
*/
|
||||
private String url;
|
||||
|
||||
/**
|
||||
* 请求类型
|
||||
*/
|
||||
private String method;
|
||||
|
||||
/**
|
||||
* IP地址
|
||||
*/
|
||||
private String ip;
|
||||
|
||||
private Object parameter;
|
||||
|
||||
private Object result;
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public Long getStartTime() {
|
||||
return startTime;
|
||||
}
|
||||
|
||||
public void setStartTime(Long startTime) {
|
||||
this.startTime = startTime;
|
||||
}
|
||||
|
||||
public Integer getSpendTime() {
|
||||
return spendTime;
|
||||
}
|
||||
|
||||
public void setSpendTime(Integer spendTime) {
|
||||
this.spendTime = spendTime;
|
||||
}
|
||||
|
||||
public String getBasePath() {
|
||||
return basePath;
|
||||
}
|
||||
|
||||
public void setBasePath(String basePath) {
|
||||
this.basePath = basePath;
|
||||
}
|
||||
|
||||
public String getUri() {
|
||||
return uri;
|
||||
}
|
||||
|
||||
public void setUri(String uri) {
|
||||
this.uri = uri;
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public String getMethod() {
|
||||
return method;
|
||||
}
|
||||
|
||||
public void setMethod(String method) {
|
||||
this.method = method;
|
||||
}
|
||||
|
||||
public String getIp() {
|
||||
return ip;
|
||||
}
|
||||
|
||||
public void setIp(String ip) {
|
||||
this.ip = ip;
|
||||
}
|
||||
|
||||
public Object getParameter() {
|
||||
return parameter;
|
||||
}
|
||||
|
||||
public void setParameter(Object parameter) {
|
||||
this.parameter = parameter;
|
||||
}
|
||||
|
||||
public Object getResult() {
|
||||
return result;
|
||||
}
|
||||
|
||||
public void setResult(Object result) {
|
||||
this.result = result;
|
||||
}
|
||||
}
|
||||
@@ -1,125 +0,0 @@
|
||||
package com.macro.mall.component;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.core.util.URLUtil;
|
||||
import cn.hutool.json.JSON;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.macro.mall.bo.WebLog;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import net.logstash.logback.marker.Markers;
|
||||
import org.aspectj.lang.JoinPoint;
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.Signature;
|
||||
import org.aspectj.lang.annotation.*;
|
||||
import org.aspectj.lang.reflect.MethodSignature;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.context.request.RequestContextHolder;
|
||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Parameter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 统一日志处理切面
|
||||
* Created by macro on 2018/4/26.
|
||||
*/
|
||||
@Aspect
|
||||
@Component
|
||||
@Order(1)
|
||||
public class WebLogAspect {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(WebLogAspect.class);
|
||||
|
||||
@Pointcut("execution(public * com.macro.mall.controller.*.*(..))")
|
||||
public void webLog() {
|
||||
}
|
||||
|
||||
@Before("webLog()")
|
||||
public void doBefore(JoinPoint joinPoint) throws Throwable {
|
||||
}
|
||||
|
||||
@AfterReturning(value = "webLog()", returning = "ret")
|
||||
public void doAfterReturning(Object ret) throws Throwable {
|
||||
}
|
||||
|
||||
@Around("webLog()")
|
||||
public Object doAround(ProceedingJoinPoint joinPoint) throws Throwable {
|
||||
long startTime = System.currentTimeMillis();
|
||||
//获取当前请求对象
|
||||
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
|
||||
HttpServletRequest request = attributes.getRequest();
|
||||
//记录请求信息(通过Logstash传入Elasticsearch)
|
||||
WebLog webLog = new WebLog();
|
||||
Object result = joinPoint.proceed();
|
||||
Signature signature = joinPoint.getSignature();
|
||||
MethodSignature methodSignature = (MethodSignature) signature;
|
||||
Method method = methodSignature.getMethod();
|
||||
if (method.isAnnotationPresent(ApiOperation.class)) {
|
||||
ApiOperation log = method.getAnnotation(ApiOperation.class);
|
||||
webLog.setDescription(log.value());
|
||||
}
|
||||
long endTime = System.currentTimeMillis();
|
||||
String urlStr = request.getRequestURL().toString();
|
||||
webLog.setBasePath(StrUtil.removeSuffix(urlStr, URLUtil.url(urlStr).getPath()));
|
||||
webLog.setIp(request.getRemoteUser());
|
||||
webLog.setMethod(request.getMethod());
|
||||
webLog.setParameter(getParameter(method, joinPoint.getArgs()));
|
||||
webLog.setResult(result);
|
||||
webLog.setSpendTime((int) (endTime - startTime));
|
||||
webLog.setStartTime(startTime);
|
||||
webLog.setUri(request.getRequestURI());
|
||||
webLog.setUrl(request.getRequestURL().toString());
|
||||
Map<String,Object> logMap = new HashMap<>();
|
||||
logMap.put("url",webLog.getUrl());
|
||||
logMap.put("method",webLog.getMethod());
|
||||
logMap.put("parameter",webLog.getParameter());
|
||||
logMap.put("spendTime",webLog.getSpendTime());
|
||||
logMap.put("description",webLog.getDescription());
|
||||
// LOGGER.info("{}", JSONUtil.parse(webLog));
|
||||
LOGGER.info(Markers.appendEntries(logMap), JSONUtil.parse(webLog).toString());
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据方法和传入的参数获取请求参数
|
||||
*/
|
||||
private Object getParameter(Method method, Object[] args) {
|
||||
List<Object> argList = new ArrayList<>();
|
||||
Parameter[] parameters = method.getParameters();
|
||||
for (int i = 0; i < parameters.length; i++) {
|
||||
//将RequestBody注解修饰的参数作为请求参数
|
||||
RequestBody requestBody = parameters[i].getAnnotation(RequestBody.class);
|
||||
if (requestBody != null) {
|
||||
argList.add(args[i]);
|
||||
}
|
||||
//将RequestParam注解修饰的参数作为请求参数
|
||||
RequestParam requestParam = parameters[i].getAnnotation(RequestParam.class);
|
||||
if (requestParam != null) {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
String key = parameters[i].getName();
|
||||
if (!StringUtils.isEmpty(requestParam.value())) {
|
||||
key = requestParam.value();
|
||||
}
|
||||
map.put(key, args[i]);
|
||||
argList.add(map);
|
||||
}
|
||||
}
|
||||
if (argList.size() == 0) {
|
||||
return null;
|
||||
} else if (argList.size() == 1) {
|
||||
return argList.get(0);
|
||||
} else {
|
||||
return argList;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,78 +0,0 @@
|
||||
package com.macro.mall.config;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import springfox.documentation.builders.ApiInfoBuilder;
|
||||
import springfox.documentation.builders.PathSelectors;
|
||||
import springfox.documentation.builders.RequestHandlerSelectors;
|
||||
import springfox.documentation.service.ApiInfo;
|
||||
import springfox.documentation.service.ApiKey;
|
||||
import springfox.documentation.service.AuthorizationScope;
|
||||
import springfox.documentation.service.SecurityReference;
|
||||
import springfox.documentation.spi.DocumentationType;
|
||||
import springfox.documentation.spi.service.contexts.SecurityContext;
|
||||
import springfox.documentation.spring.web.plugins.Docket;
|
||||
import springfox.documentation.swagger2.annotations.EnableSwagger2;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Swagger API文档相关配置
|
||||
* Created by macro on 2018/4/26.
|
||||
*/
|
||||
@Configuration
|
||||
@EnableSwagger2
|
||||
public class Swagger2Config {
|
||||
@Bean
|
||||
public Docket createRestApi(){
|
||||
return new Docket(DocumentationType.SWAGGER_2)
|
||||
.apiInfo(apiInfo())
|
||||
.select()
|
||||
.apis(RequestHandlerSelectors.basePackage("com.macro.mall.controller"))
|
||||
.paths(PathSelectors.any())
|
||||
.build()
|
||||
.securitySchemes(securitySchemes())
|
||||
.securityContexts(securityContexts());
|
||||
}
|
||||
|
||||
private ApiInfo apiInfo() {
|
||||
return new ApiInfoBuilder()
|
||||
.title("mall后台系统")
|
||||
.description("mall后台模块")
|
||||
.contact("macro")
|
||||
.version("1.0")
|
||||
.build();
|
||||
}
|
||||
|
||||
private List<ApiKey> securitySchemes() {
|
||||
//设置请求头信息
|
||||
List<ApiKey> result = new ArrayList<>();
|
||||
ApiKey apiKey = new ApiKey("Authorization", "Authorization", "header");
|
||||
result.add(apiKey);
|
||||
return result;
|
||||
}
|
||||
|
||||
private List<SecurityContext> securityContexts() {
|
||||
//设置需要登录认证的路径
|
||||
List<SecurityContext> result = new ArrayList<>();
|
||||
result.add(getContextByPath("/*/.*"));
|
||||
return result;
|
||||
}
|
||||
|
||||
private SecurityContext getContextByPath(String pathRegex){
|
||||
return SecurityContext.builder()
|
||||
.securityReferences(defaultAuth())
|
||||
.forPaths(PathSelectors.regex(pathRegex))
|
||||
.build();
|
||||
}
|
||||
|
||||
private List<SecurityReference> defaultAuth() {
|
||||
List<SecurityReference> result = new ArrayList<>();
|
||||
AuthorizationScope authorizationScope = new AuthorizationScope("global", "accessEverything");
|
||||
AuthorizationScope[] authorizationScopes = new AuthorizationScope[1];
|
||||
authorizationScopes[0] = authorizationScope;
|
||||
result.add(new SecurityReference("Authorization", authorizationScopes));
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.macro.mall.config;
|
||||
|
||||
import com.macro.mall.common.config.BaseSwaggerConfig;
|
||||
import com.macro.mall.common.domain.SwaggerProperties;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import springfox.documentation.swagger2.annotations.EnableSwagger2;
|
||||
|
||||
/**
|
||||
* Swagger API文档相关配置
|
||||
* Created by macro on 2018/4/26.
|
||||
*/
|
||||
@Configuration
|
||||
@EnableSwagger2
|
||||
public class SwaggerConfig extends BaseSwaggerConfig {
|
||||
|
||||
@Override
|
||||
public SwaggerProperties swaggerProperties() {
|
||||
return SwaggerProperties.builder()
|
||||
.apiBasePackage("com.macro.mall.controller")
|
||||
.title("mall后台系统")
|
||||
.description("mall后台相关接口文档")
|
||||
.contactName("macro")
|
||||
.version("1.0")
|
||||
.enableSecurity(true)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,13 @@
|
||||
package com.macro.mall.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import com.macro.mall.common.service.RedisService;
|
||||
import com.macro.mall.dao.UmsAdminRoleRelationDao;
|
||||
import com.macro.mall.mapper.UmsAdminRoleRelationMapper;
|
||||
import com.macro.mall.model.UmsAdmin;
|
||||
import com.macro.mall.model.UmsAdminRoleRelation;
|
||||
import com.macro.mall.model.UmsAdminRoleRelationExample;
|
||||
import com.macro.mall.model.UmsResource;
|
||||
import com.macro.mall.security.service.RedisService;
|
||||
import com.macro.mall.service.UmsAdminCacheService;
|
||||
import com.macro.mall.service.UmsAdminService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
@@ -17,4 +17,12 @@ spring:
|
||||
database: 0 # Redis数据库索引(默认为0)
|
||||
port: 6379 # Redis服务器连接端口
|
||||
password: # Redis服务器连接密码(默认为空)
|
||||
timeout: 300ms # 连接超时时间(毫秒)
|
||||
timeout: 300ms # 连接超时时间(毫秒)
|
||||
|
||||
logging:
|
||||
level:
|
||||
root: info
|
||||
com.macro.mall: debug
|
||||
|
||||
logstash:
|
||||
host: localhost
|
||||
@@ -20,4 +20,11 @@ spring:
|
||||
timeout: 300ms # 连接超时时间(毫秒)
|
||||
|
||||
logging:
|
||||
path: /var/logs #配置日志生成路径
|
||||
file:
|
||||
path: /var/logs
|
||||
level:
|
||||
root: info
|
||||
com.macro.mall: info
|
||||
|
||||
logstash:
|
||||
host: logstash
|
||||
@@ -1,4 +1,6 @@
|
||||
spring:
|
||||
application:
|
||||
name: mall-admin
|
||||
profiles:
|
||||
active: dev #默认为开发环境
|
||||
servlet:
|
||||
@@ -15,7 +17,7 @@ jwt:
|
||||
tokenHeader: Authorization #JWT存储的请求头
|
||||
secret: mall-admin-secret #JWT加解密使用的密钥
|
||||
expiration: 604800 #JWT的超期限时间(60*60*24*7)
|
||||
tokenHead: 'Bearer ' #JWT负载中拿到开头
|
||||
tokenHead: 'Bearer ' #JWT负载中拿到开头
|
||||
|
||||
redis:
|
||||
database: mall
|
||||
@@ -63,10 +65,3 @@ minio:
|
||||
bucketName: mall #存储桶名称
|
||||
accessKey: minioadmin #访问的key
|
||||
secretKey: minioadmin #访问的秘钥
|
||||
|
||||
logging:
|
||||
level:
|
||||
root: info #日志配置DEBUG,INFO,WARN,ERROR
|
||||
com.macro.mall: debug
|
||||
# file: demo_log.log #配置日志生成路径
|
||||
# path: /var/logs #配置日志文件名称
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE configuration>
|
||||
<configuration>
|
||||
<include resource="org/springframework/boot/logging/logback/defaults.xml"/>
|
||||
<include resource="org/springframework/boot/logging/logback/console-appender.xml"/>
|
||||
<!--应用名称-->
|
||||
<property name="APP_NAME" value="mall-admin"/>
|
||||
<!--日志文件保存路径-->
|
||||
<property name="LOG_FILE_PATH" value="${LOG_FILE:-${LOG_PATH:-${LOG_TEMP:-${java.io.tmpdir:-/tmp}}}/logs}"/>
|
||||
<contextName>${APP_NAME}</contextName>
|
||||
<!--每天记录日志到文件appender-->
|
||||
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||
<fileNamePattern>${LOG_FILE_PATH}/${APP_NAME}-%d{yyyy-MM-dd}.log</fileNamePattern>
|
||||
<maxHistory>30</maxHistory>
|
||||
</rollingPolicy>
|
||||
<encoder>
|
||||
<pattern>${FILE_LOG_PATTERN}</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
<!--输出到logstash的appender-->
|
||||
<appender name="LOGSTASH" class="net.logstash.logback.appender.LogstashTcpSocketAppender">
|
||||
<destination>localhost:4560</destination>
|
||||
<encoder charset="UTF-8" class="net.logstash.logback.encoder.LogstashEncoder"/>
|
||||
</appender>
|
||||
<root level="INFO">
|
||||
<appender-ref ref="CONSOLE"/>
|
||||
<appender-ref ref="FILE"/>
|
||||
<appender-ref ref="LOGSTASH"/>
|
||||
</root>
|
||||
</configuration>
|
||||
Reference in New Issue
Block a user