review code.
This commit is contained in:
@@ -1,6 +1,5 @@
|
|||||||
package com.orion.ops.framework.datasource.config;
|
package com.orion.ops.framework.datasource.config;
|
||||||
|
|
||||||
import com.alibaba.druid.pool.DruidDataSource;
|
|
||||||
import com.alibaba.druid.spring.boot.autoconfigure.properties.DruidStatProperties;
|
import com.alibaba.druid.spring.boot.autoconfigure.properties.DruidStatProperties;
|
||||||
import com.orion.ops.framework.datasource.core.filter.DruidAdRemoveFilter;
|
import com.orion.ops.framework.datasource.core.filter.DruidAdRemoveFilter;
|
||||||
import org.springframework.boot.autoconfigure.AutoConfiguration;
|
import org.springframework.boot.autoconfigure.AutoConfiguration;
|
||||||
@@ -10,8 +9,6 @@ import org.springframework.boot.web.servlet.FilterRegistrationBean;
|
|||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||||
|
|
||||||
import javax.sql.DataSource;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 数据源配置类
|
* 数据源配置类
|
||||||
*
|
*
|
||||||
@@ -24,14 +21,6 @@ import javax.sql.DataSource;
|
|||||||
@EnableConfigurationProperties(DruidStatProperties.class)
|
@EnableConfigurationProperties(DruidStatProperties.class)
|
||||||
public class OrionDatasourceAutoConfiguration {
|
public class OrionDatasourceAutoConfiguration {
|
||||||
|
|
||||||
/**
|
|
||||||
* @return druid 数据源
|
|
||||||
*/
|
|
||||||
@Bean
|
|
||||||
public DataSource druidDataSource() {
|
|
||||||
return new DruidDataSource();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param properties 配置
|
* @param properties 配置
|
||||||
* @return druid 广告过滤器
|
* @return druid 广告过滤器
|
||||||
|
|||||||
@@ -6,13 +6,14 @@ import com.orion.ops.framework.log.core.interceptor.LogPrinterInterceptor;
|
|||||||
import com.orion.ops.framework.log.core.interceptor.PrettyLogPrinterInterceptor;
|
import com.orion.ops.framework.log.core.interceptor.PrettyLogPrinterInterceptor;
|
||||||
import com.orion.ops.framework.log.core.interceptor.RowLogPrinterInterceptor;
|
import com.orion.ops.framework.log.core.interceptor.RowLogPrinterInterceptor;
|
||||||
import org.springframework.aop.aspectj.AspectJExpressionPointcutAdvisor;
|
import org.springframework.aop.aspectj.AspectJExpressionPointcutAdvisor;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
|
||||||
import org.springframework.boot.autoconfigure.AutoConfiguration;
|
import org.springframework.boot.autoconfigure.AutoConfiguration;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 全局日志打印配置类
|
* 全局日志打印配置类
|
||||||
*
|
*
|
||||||
@@ -24,37 +25,36 @@ import org.springframework.context.annotation.Bean;
|
|||||||
@EnableConfigurationProperties(LogPrinterConfig.class)
|
@EnableConfigurationProperties(LogPrinterConfig.class)
|
||||||
public class OrionLogPrinterConfiguration {
|
public class OrionLogPrinterConfiguration {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private LogPrinterConfig config;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param config config
|
|
||||||
* @return 美化日志打印器
|
* @return 美化日志打印器
|
||||||
*/
|
*/
|
||||||
@Bean(initMethod = "init")
|
@Bean(initMethod = "init")
|
||||||
@ConditionalOnProperty(value = "logging.printer.mode", havingValue = "pretty")
|
@ConditionalOnProperty(value = "orion.logging.printer.mode", havingValue = "pretty")
|
||||||
public LogPrinterInterceptor prettyPrinter(LogPrinterConfig config) {
|
public LogPrinterInterceptor prettyPrinter() {
|
||||||
return new PrettyLogPrinterInterceptor(config);
|
return new PrettyLogPrinterInterceptor(config);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param config config
|
|
||||||
* @return 单行日志打印器
|
* @return 单行日志打印器
|
||||||
*/
|
*/
|
||||||
@Bean(initMethod = "init")
|
@Bean(initMethod = "init")
|
||||||
@ConditionalOnProperty(value = "logging.printer.mode", havingValue = "row")
|
@ConditionalOnProperty(value = "orion.logging.printer.mode", havingValue = "row")
|
||||||
public LogPrinterInterceptor rowPrinter(LogPrinterConfig config) {
|
public LogPrinterInterceptor rowPrinter() {
|
||||||
return new RowLogPrinterInterceptor(config);
|
return new RowLogPrinterInterceptor(config);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param logPrinterInterceptor logPrinterInterceptor
|
* @param logPrinterInterceptor logPrinterInterceptor
|
||||||
* @param expression 切面表达式
|
|
||||||
* @return 日志打印切面
|
* @return 日志打印切面
|
||||||
*/
|
*/
|
||||||
@Bean
|
@Bean
|
||||||
@ConditionalOnBean(LogPrinterInterceptor.class)
|
@ConditionalOnBean(LogPrinterInterceptor.class)
|
||||||
public AspectJExpressionPointcutAdvisor logPrinterAdvisor(LogPrinterInterceptor logPrinterInterceptor,
|
public AspectJExpressionPointcutAdvisor logPrinterAdvisor(LogPrinterInterceptor logPrinterInterceptor) {
|
||||||
@Value("${logging.printer.expression}") String expression) {
|
|
||||||
AspectJExpressionPointcutAdvisor advisor = new AspectJExpressionPointcutAdvisor();
|
AspectJExpressionPointcutAdvisor advisor = new AspectJExpressionPointcutAdvisor();
|
||||||
advisor.setExpression(expression);
|
advisor.setExpression(config.getExpression());
|
||||||
advisor.setAdvice(logPrinterInterceptor);
|
advisor.setAdvice(logPrinterInterceptor);
|
||||||
advisor.setOrder(InterceptorOrderConst.LOG_FILTER);
|
advisor.setOrder(InterceptorOrderConst.LOG_FILTER);
|
||||||
return advisor;
|
return advisor;
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import java.util.List;
|
|||||||
* @since 2023/6/28 22:36
|
* @since 2023/6/28 22:36
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
@ConfigurationProperties("logging.printer")
|
@ConfigurationProperties("orion.logging.printer")
|
||||||
public class LogPrinterConfig {
|
public class LogPrinterConfig {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -27,6 +27,11 @@ public class LogPrinterConfig {
|
|||||||
*/
|
*/
|
||||||
private List<String> headers;
|
private List<String> headers;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 切面表达式
|
||||||
|
*/
|
||||||
|
private String expression;
|
||||||
|
|
||||||
public void setField(LogPrinterFieldConfig field) {
|
public void setField(LogPrinterFieldConfig field) {
|
||||||
this.field = field;
|
this.field = field;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,35 +1,35 @@
|
|||||||
{
|
{
|
||||||
"groups": [
|
"groups": [
|
||||||
{
|
{
|
||||||
"name": "logging.printer",
|
"name": "orion.logging.printer",
|
||||||
"type": "com.orion.ops.framework.log.core.config.LogPrinterConfig",
|
"type": "com.orion.ops.framework.log.core.config.LogPrinterConfig",
|
||||||
"sourceType": "com.orion.ops.framework.log.core.config.LogPrinterConfig"
|
"sourceType": "com.orion.ops.framework.log.core.config.LogPrinterConfig"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"properties": [
|
"properties": [
|
||||||
{
|
{
|
||||||
"name": "logging.printer.mode",
|
"name": "orion.logging.printer.mode",
|
||||||
"type": "com.orion.ops.framework.log.core.enums.LogPrinterMode",
|
"type": "com.orion.ops.framework.log.core.enums.LogPrinterMode",
|
||||||
"description": "日志打印模型.",
|
"description": "日志打印模型.",
|
||||||
"defaultValue": "NONE"
|
"defaultValue": "NONE"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "logging.printer.expression",
|
"name": "orion.logging.printer.expression",
|
||||||
"type": "java.lang.String",
|
"type": "java.lang.String",
|
||||||
"description": "aspectj 表达式."
|
"description": "aspectj 表达式."
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "logging.printer.headers",
|
"name": "orion.logging.printer.headers",
|
||||||
"type": "java.util.List",
|
"type": "java.util.List",
|
||||||
"description": "需要打印的 HttpHandlers."
|
"description": "需要打印的 HttpHandlers."
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "logging.printer.field.ignore",
|
"name": "orion.logging.printer.field.ignore",
|
||||||
"type": "java.util.List",
|
"type": "java.util.List",
|
||||||
"description": "忽略打印的字段."
|
"description": "忽略打印的字段."
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "logging.printer.field.desensitize",
|
"name": "orion.logging.printer.field.desensitize",
|
||||||
"type": "java.util.List",
|
"type": "java.util.List",
|
||||||
"description": "需要脱敏的字段."
|
"description": "需要脱敏的字段."
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ public class PermitAllAnnotationAuthorizeRequestsCustomizer extends AuthorizeReq
|
|||||||
Set<String> deleteList = new HashSet<>();
|
Set<String> deleteList = new HashSet<>();
|
||||||
Set<String> requestList = new HashSet<>();
|
Set<String> requestList = new HashSet<>();
|
||||||
// 获取 RequestMappingHandlerMapping
|
// 获取 RequestMappingHandlerMapping
|
||||||
RequestMappingHandlerMapping requestMappingHandlerMapping = applicationContext.getBean(RequestMappingHandlerMapping.class);
|
RequestMappingHandlerMapping requestMappingHandlerMapping = applicationContext.getBean("requestMappingHandlerMapping", RequestMappingHandlerMapping.class);
|
||||||
// 获得接口对应的 HandlerMethod
|
// 获得接口对应的 HandlerMethod
|
||||||
Map<RequestMappingInfo, HandlerMethod> handlerMethodMap = requestMappingHandlerMapping.getHandlerMethods();
|
Map<RequestMappingInfo, HandlerMethod> handlerMethodMap = requestMappingHandlerMapping.getHandlerMethods();
|
||||||
// 获得有 @PermitAll 注解的接口
|
// 获得有 @PermitAll 注解的接口
|
||||||
|
|||||||
@@ -20,10 +20,6 @@ import java.io.IOException;
|
|||||||
*/
|
*/
|
||||||
public class TraceIdFilter extends OncePerRequestFilter {
|
public class TraceIdFilter extends OncePerRequestFilter {
|
||||||
|
|
||||||
private static final String TRACE_ID_HEADER = "trace-id";
|
|
||||||
|
|
||||||
private static final String TRACE_ID_MDC = "tid";
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
|
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
|
||||||
try {
|
try {
|
||||||
@@ -32,9 +28,9 @@ public class TraceIdFilter extends OncePerRequestFilter {
|
|||||||
// 设置应用上下文
|
// 设置应用上下文
|
||||||
TraceIdHolder.set(traceId);
|
TraceIdHolder.set(traceId);
|
||||||
// 设置日志上下文
|
// 设置日志上下文
|
||||||
MDC.put(TRACE_ID_MDC, traceId);
|
MDC.put(TraceIdHolder.TRACE_ID_MDC, traceId);
|
||||||
// 设置响应头
|
// 设置响应头
|
||||||
response.setHeader(TRACE_ID_HEADER, traceId);
|
response.setHeader(TraceIdHolder.TRACE_ID_HEADER, traceId);
|
||||||
// 执行请求
|
// 执行请求
|
||||||
filterChain.doFilter(request, response);
|
filterChain.doFilter(request, response);
|
||||||
} finally {
|
} finally {
|
||||||
|
|||||||
Reference in New Issue
Block a user