fix: 修复定时任务写在controller时,不生效问题
This commit is contained in:
@@ -52,13 +52,15 @@ public class DataSourceAop {
|
||||
@Before("log()")
|
||||
public void doBefore(JoinPoint joinPoint) {
|
||||
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
|
||||
HttpServletRequest request = attributes.getRequest();
|
||||
if (isMulti) {
|
||||
String key = request.getParameter("datasourceKey");
|
||||
if (StringUtils.isBlank(key)) {
|
||||
DBContextHolder.setDataSource(DataUnit.MASTER);
|
||||
} else {
|
||||
DBContextHolder.setDataSource(key);
|
||||
if (attributes != null) {
|
||||
HttpServletRequest request = attributes.getRequest();
|
||||
if (isMulti) {
|
||||
String key = request.getParameter("datasourceKey");
|
||||
if (StringUtils.isBlank(key)) {
|
||||
DBContextHolder.setDataSource(DataUnit.MASTER);
|
||||
} else {
|
||||
DBContextHolder.setDataSource(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,38 +45,42 @@ public class RequestLogAspect {
|
||||
public Object doAround(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
|
||||
|
||||
long start = System.currentTimeMillis();
|
||||
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
|
||||
HttpServletRequest request = attributes.getRequest();
|
||||
Object result = proceedingJoinPoint.proceed();
|
||||
|
||||
if (frameConfig.getShowControllerLog()) {
|
||||
RequestInfo requestInfo = new RequestInfo();
|
||||
requestInfo.setIp(request.getRemoteAddr());
|
||||
requestInfo.setUrl(request.getRequestURL().toString());
|
||||
requestInfo.setHttpMethod(request.getMethod());
|
||||
requestInfo.setClassMethod(String.format("%s.%s", proceedingJoinPoint.getSignature().getDeclaringTypeName(),
|
||||
proceedingJoinPoint.getSignature().getName()));
|
||||
requestInfo.setRequestParams(getRequestParamsByProceedingJoinPoint(proceedingJoinPoint));
|
||||
requestInfo.setResult(result);
|
||||
requestInfo.setTimeCost(System.currentTimeMillis() - start);
|
||||
LOGGER.info("Request Info : {}", JSON.toJSONString(requestInfo));
|
||||
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
|
||||
if (attributes != null) {
|
||||
HttpServletRequest request = attributes.getRequest();
|
||||
if (frameConfig.getShowControllerLog()) {
|
||||
RequestInfo requestInfo = new RequestInfo();
|
||||
requestInfo.setIp(request.getRemoteAddr());
|
||||
requestInfo.setUrl(request.getRequestURL().toString());
|
||||
requestInfo.setHttpMethod(request.getMethod());
|
||||
requestInfo.setClassMethod(String.format("%s.%s", proceedingJoinPoint.getSignature().getDeclaringTypeName(),
|
||||
proceedingJoinPoint.getSignature().getName()));
|
||||
requestInfo.setRequestParams(getRequestParamsByProceedingJoinPoint(proceedingJoinPoint));
|
||||
requestInfo.setResult(result);
|
||||
requestInfo.setTimeCost(System.currentTimeMillis() - start);
|
||||
LOGGER.info("Request Info : {}", JSON.toJSONString(requestInfo));
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@AfterThrowing(pointcut = "requestServer()", throwing = "e")
|
||||
public void doAfterThrow(JoinPoint joinPoint, RuntimeException e) {
|
||||
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
|
||||
HttpServletRequest request = attributes.getRequest();
|
||||
RequestErrorInfo requestErrorInfo = new RequestErrorInfo();
|
||||
requestErrorInfo.setIp(request.getRemoteAddr());
|
||||
requestErrorInfo.setUrl(request.getRequestURL().toString());
|
||||
requestErrorInfo.setHttpMethod(request.getMethod());
|
||||
requestErrorInfo.setClassMethod(String.format("%s.%s", joinPoint.getSignature().getDeclaringTypeName(),
|
||||
joinPoint.getSignature().getName()));
|
||||
requestErrorInfo.setRequestParams(getRequestParamsByJoinPoint(joinPoint));
|
||||
requestErrorInfo.setException(e);
|
||||
LOGGER.error("Error Request Info : {}", JSON.toJSONString(requestErrorInfo));
|
||||
if (attributes != null) {
|
||||
HttpServletRequest request = attributes.getRequest();
|
||||
RequestErrorInfo requestErrorInfo = new RequestErrorInfo();
|
||||
requestErrorInfo.setIp(request.getRemoteAddr());
|
||||
requestErrorInfo.setUrl(request.getRequestURL().toString());
|
||||
requestErrorInfo.setHttpMethod(request.getMethod());
|
||||
requestErrorInfo.setClassMethod(String.format("%s.%s", joinPoint.getSignature().getDeclaringTypeName(),
|
||||
joinPoint.getSignature().getName()));
|
||||
requestErrorInfo.setRequestParams(getRequestParamsByJoinPoint(joinPoint));
|
||||
requestErrorInfo.setException(e);
|
||||
LOGGER.error("Error Request Info : {}", JSON.toJSONString(requestErrorInfo));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -230,25 +230,25 @@
|
||||
</profile>
|
||||
</profiles>
|
||||
<distributionManagement>
|
||||
<repository>
|
||||
<id>releases</id>
|
||||
<name>Releases</name>
|
||||
<url>http://192.168.0.123:8081/repository/maven-releases/</url>
|
||||
</repository>
|
||||
<snapshotRepository>
|
||||
<id>snapshots</id>
|
||||
<name>Snapshot</name>
|
||||
<url>http://192.168.0.123:8081/repository/maven-snapshots/</url>
|
||||
</snapshotRepository>
|
||||
<!-- <repository>-->
|
||||
<!-- <id>releases-hc</id>-->
|
||||
<!-- <id>releases</id>-->
|
||||
<!-- <name>Releases</name>-->
|
||||
<!-- <url>https://qs.taixingyiji.com:8082/repository/maven-releases/</url>-->
|
||||
<!-- <url>http://192.168.0.123:8081/repository/maven-releases/</url>-->
|
||||
<!-- </repository>-->
|
||||
<!-- <snapshotRepository>-->
|
||||
<!-- <id>snapshots-hc</id>-->
|
||||
<!-- <id>snapshots</id>-->
|
||||
<!-- <name>Snapshot</name>-->
|
||||
<!-- <url>https://qs.taixingyiji.com:8082/repository/maven-snapshots/</url>-->
|
||||
<!-- <url>http://192.168.0.123:8081/repository/maven-snapshots/</url>-->
|
||||
<!-- </snapshotRepository>-->
|
||||
<repository>
|
||||
<id>releases-hc</id>
|
||||
<name>Releases</name>
|
||||
<url>https://qs.taixingyiji.com:8082/repository/maven-releases/</url>
|
||||
</repository>
|
||||
<snapshotRepository>
|
||||
<id>snapshots-hc</id>
|
||||
<name>Snapshot</name>
|
||||
<url>https://qs.taixingyiji.com:8082/repository/maven-snapshots/</url>
|
||||
</snapshotRepository>
|
||||
</distributionManagement>
|
||||
</project>
|
||||
|
||||
Reference in New Issue
Block a user