merge
This commit is contained in:
@@ -1,8 +1,7 @@
|
||||
package com.xwbing.configuration;
|
||||
|
||||
import com.xwbing.util.CommonDataUtil;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
@@ -13,14 +12,13 @@ import org.springframework.scheduling.annotation.Scheduled;
|
||||
* 创建时间: 2017/5/10 16:36
|
||||
* 作者: xiangwb
|
||||
*/
|
||||
@Slf4j
|
||||
@Configuration
|
||||
@EnableScheduling//启用定时任务
|
||||
public class SchedulingConfig {
|
||||
private final Logger logger = LoggerFactory.getLogger(SchedulingConfig.class);
|
||||
|
||||
@Scheduled(cron = "0 0 6 * * ? ")//每天6点执行定时任务
|
||||
public void scheduler() {
|
||||
logger.info("清除公共数据类过期数据===================");
|
||||
log.info("清除公共数据类过期数据===================");
|
||||
CommonDataUtil.clearExpiryData();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,8 +2,7 @@ package com.xwbing.configuration;
|
||||
|
||||
import com.xwbing.handler.FormRepeatFilter;
|
||||
import com.xwbing.util.captcha.CaptchaServlet;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.boot.web.servlet.FilterRegistrationBean;
|
||||
import org.springframework.boot.web.servlet.ServletRegistrationBean;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
@@ -15,13 +14,12 @@ import org.springframework.context.annotation.Configuration;
|
||||
* 创建时间: 2017/5/10 16:36
|
||||
* 作者: xiangwb
|
||||
*/
|
||||
@Slf4j
|
||||
@Configuration
|
||||
public class ServletFilterConfig {
|
||||
private final Logger logger = LoggerFactory.getLogger(ServletFilterConfig.class);
|
||||
|
||||
@Bean
|
||||
public ServletRegistrationBean captchaServlet() {
|
||||
logger.info("注册登陆验证码servlet ======================= ");
|
||||
log.info("注册登陆验证码servlet ======================= ");
|
||||
ServletRegistrationBean registration = new ServletRegistrationBean(new CaptchaServlet());
|
||||
registration.addUrlMappings("/captcha");
|
||||
return registration;
|
||||
@@ -31,7 +29,7 @@ public class ServletFilterConfig {
|
||||
|
||||
@Bean
|
||||
public FilterRegistrationBean formSaveFilter() {
|
||||
logger.info("注册表单重复提交过滤器formSaveFilter ======================= ");
|
||||
log.info("注册表单重复提交过滤器formSaveFilter ======================= ");
|
||||
FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean(new FormRepeatFilter());
|
||||
filterRegistrationBean.addUrlPatterns("/*");
|
||||
filterRegistrationBean.addInitParameter("excludePath", "/doc,/captcha,/v2/api-docs,/swagger-resources,/configuration/ui,/configuration/security,/druid");
|
||||
|
||||
@@ -14,9 +14,8 @@ import com.xwbing.util.JsonResult;
|
||||
import com.xwbing.util.RSAUtil;
|
||||
import com.xwbing.util.RestMessage;
|
||||
import io.swagger.annotations.Api;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
@@ -32,6 +31,7 @@ import java.util.concurrent.CompletableFuture;
|
||||
* 创建时间: 2017/5/5 9:21
|
||||
* 作者: xiangwb
|
||||
*/
|
||||
@Slf4j
|
||||
@Api(tags = "testApi", description = "测试相关接口")
|
||||
@RestController
|
||||
@RequestMapping("/test/")
|
||||
@@ -46,7 +46,6 @@ public class TestControl {
|
||||
private CookieSessionService cookieSessionService;
|
||||
@Resource
|
||||
private Sender sender;
|
||||
private final Logger logger = LoggerFactory.getLogger(TestControl.class);
|
||||
|
||||
@GetMapping("send")
|
||||
public void sendM(@RequestParam String[] msg) {
|
||||
@@ -58,14 +57,14 @@ public class TestControl {
|
||||
public void redis() {
|
||||
redisService.set("redis", "xwbing");
|
||||
String s = redisService.get("redis");
|
||||
logger.info("redis获取的数据为:" + s);
|
||||
log.info("redis获取的数据为:" + s);
|
||||
}
|
||||
|
||||
@LogInfo("log功能测试")
|
||||
@GetMapping("log")
|
||||
public void log() {
|
||||
logger.info("info test");
|
||||
logger.error("error test");
|
||||
log.info("info test");
|
||||
log.error("error test");
|
||||
}
|
||||
|
||||
@LogInfo("获取快递列表")
|
||||
|
||||
@@ -10,9 +10,8 @@ import com.xwbing.util.JsonResult;
|
||||
import com.xwbing.util.RestMessage;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
@@ -25,11 +24,11 @@ import java.util.List;
|
||||
* 创建时间: 2017/5/10 16:36
|
||||
* 作者: xiangwb
|
||||
*/
|
||||
@Slf4j
|
||||
@Api(tags = "configApi", description = "系统配置相关接口")
|
||||
@RestController
|
||||
@RequestMapping("/config/")
|
||||
public class SysConfigControl {
|
||||
private final Logger logger = LoggerFactory.getLogger(SysConfigControl.class);
|
||||
@Resource
|
||||
private SysConfigService sysConfigService;
|
||||
|
||||
@@ -37,7 +36,7 @@ public class SysConfigControl {
|
||||
@PostMapping("save")
|
||||
public JSONObject save(@RequestBody @Valid SysConfig sysConfig) {
|
||||
String logMsg = "新增系统配置信息";
|
||||
logger.info(logMsg);
|
||||
log.info(logMsg);
|
||||
RestMessage result = sysConfigService.save(sysConfig);
|
||||
return JsonResult.toJSONObj(result);
|
||||
}
|
||||
@@ -46,7 +45,7 @@ public class SysConfigControl {
|
||||
@DeleteMapping("removeByCode/{code}")
|
||||
public JSONObject removeByCode(@PathVariable String code) {
|
||||
String logMsg = "根据code删除系统配置信息";
|
||||
logger.info(logMsg + " code:{}", code);
|
||||
log.info(logMsg + " code:{}", code);
|
||||
if (StringUtils.isEmpty(code)) {
|
||||
return JsonResult.toJSONObj("code不能为空");
|
||||
}
|
||||
@@ -58,7 +57,7 @@ public class SysConfigControl {
|
||||
@PutMapping("update")
|
||||
public JSONObject update(@RequestBody @Valid SysConfig sysConfig) {
|
||||
String logMsg = "修改系统配置信息";
|
||||
logger.info(logMsg);
|
||||
log.info(logMsg);
|
||||
if (StringUtils.isEmpty(sysConfig.getCode())) {
|
||||
return JsonResult.toJSONObj("配置项的code不能为空");
|
||||
}
|
||||
@@ -70,7 +69,7 @@ public class SysConfigControl {
|
||||
@GetMapping("getByCode")
|
||||
public JSONObject getByCode(@RequestParam String code) {
|
||||
String logMsg = "根据code查找系统配置信息";
|
||||
logger.info(logMsg + " code:{}", code);
|
||||
log.info(logMsg + " code:{}", code);
|
||||
if (StringUtils.isEmpty(code)) {
|
||||
return JsonResult.toJSONObj("code不能为空");
|
||||
}
|
||||
@@ -85,7 +84,7 @@ public class SysConfigControl {
|
||||
@GetMapping("listByEnable")
|
||||
public JSONObject listByEnable(@RequestParam String enable) {
|
||||
String logMsg = "根据是否启用查找配置列表";
|
||||
logger.info(logMsg + " enable:{}", enable);
|
||||
log.info(logMsg + " enable:{}", enable);
|
||||
if (StringUtils.isEmpty(enable)) {
|
||||
return JsonResult.toJSONObj("是否启用不能为空");
|
||||
}
|
||||
|
||||
@@ -5,8 +5,7 @@ import com.xwbing.exception.BusinessException;
|
||||
import com.xwbing.exception.PayException;
|
||||
import com.xwbing.exception.UtilException;
|
||||
import com.xwbing.util.JsonResult;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.context.support.DefaultMessageSourceResolvable;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.validation.BindException;
|
||||
@@ -32,8 +31,8 @@ import java.util.stream.Collectors;
|
||||
*/
|
||||
// 作用在所有注解了@RequestMapping的控制器的方法上
|
||||
@ControllerAdvice
|
||||
@Slf4j
|
||||
public class GlobalExceptionHandler {
|
||||
private final Logger logger = LoggerFactory.getLogger(GlobalExceptionHandler.class);
|
||||
|
||||
/**
|
||||
* 自定义业务异常
|
||||
@@ -47,7 +46,7 @@ public class GlobalExceptionHandler {
|
||||
@ResponseStatus(value = HttpStatus.OK)
|
||||
@ResponseBody
|
||||
public JSONObject handlerBusinessException(BusinessException ex) {
|
||||
logger.error(ex.getMessage());
|
||||
log.error(ex.getMessage());
|
||||
return JsonResult.toJSONObj(ex.getMessage());
|
||||
}
|
||||
|
||||
@@ -61,7 +60,7 @@ public class GlobalExceptionHandler {
|
||||
@ResponseStatus(value = HttpStatus.OK)
|
||||
@ResponseBody
|
||||
public JSONObject handlerUtilException(UtilException ex) {
|
||||
logger.error(ex.getMessage());
|
||||
log.error(ex.getMessage());
|
||||
return JsonResult.toJSONObj(ex.getMessage());
|
||||
}
|
||||
|
||||
@@ -75,7 +74,7 @@ public class GlobalExceptionHandler {
|
||||
@ResponseStatus(value = HttpStatus.OK)
|
||||
@ResponseBody
|
||||
public JSONObject handlerPayException(PayException ex) {
|
||||
logger.error(ex.getMessage());
|
||||
log.error(ex.getMessage());
|
||||
return JsonResult.toJSONObj(ex.getMessage());
|
||||
}
|
||||
|
||||
@@ -91,7 +90,7 @@ public class GlobalExceptionHandler {
|
||||
public JSONObject handlerCompletionException(CompletionException ex) {
|
||||
Throwable cause = ex.getCause();
|
||||
String errorMessages = cause.getMessage();
|
||||
logger.error(errorMessages);
|
||||
log.error(errorMessages);
|
||||
String detail = cause.toString();
|
||||
if (!detail.contains("BusinessException")) {
|
||||
errorMessages = "异步获取数据出错";
|
||||
@@ -112,7 +111,7 @@ public class GlobalExceptionHandler {
|
||||
public JSONObject handlerBindException(HttpServletRequest request, HttpServletResponse response, BindException ex) {
|
||||
List<ObjectError> list = ex.getAllErrors();
|
||||
String errorMessages = list.stream().map(DefaultMessageSourceResolvable::getDefaultMessage).collect(Collectors.joining("&&"));
|
||||
logger.error(errorMessages);
|
||||
log.error(errorMessages);
|
||||
response.setStatus(HttpStatus.OK.value());
|
||||
return JsonResult.toJSONObj(errorMessages);
|
||||
}
|
||||
@@ -130,7 +129,7 @@ public class GlobalExceptionHandler {
|
||||
BindingResult bindingResult = ex.getBindingResult();
|
||||
List<ObjectError> allErrors = bindingResult.getAllErrors();
|
||||
String errorMessages = allErrors.stream().map(DefaultMessageSourceResolvable::getDefaultMessage).collect(Collectors.joining("&&"));
|
||||
logger.error(errorMessages);
|
||||
log.error(errorMessages);
|
||||
return JsonResult.toJSONObj(errorMessages);
|
||||
}
|
||||
|
||||
@@ -144,7 +143,7 @@ public class GlobalExceptionHandler {
|
||||
@ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR)
|
||||
@ResponseBody
|
||||
public JSONObject handlerException(Exception ex) {
|
||||
logger.error(ex.getMessage());
|
||||
log.error(ex.getMessage());
|
||||
return JsonResult.toJSONObj("系统异常,请联系管理员");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
package com.xwbing.handler;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.xwbing.configuration.DispatcherServletConfig;
|
||||
import com.xwbing.util.CommonDataUtil;
|
||||
import com.xwbing.util.RestMessage;
|
||||
import com.xwbing.util.ThreadLocalUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
@@ -24,8 +22,8 @@ import java.util.Set;
|
||||
* 创建时间: 2017/5/10 16:36
|
||||
* 作者: xiangwb
|
||||
*/
|
||||
@Slf4j
|
||||
public class LoginInterceptor extends HandlerInterceptorAdapter {
|
||||
private final Logger logger = LoggerFactory.getLogger(DispatcherServletConfig.class);
|
||||
private static final Set<String> SET = new HashSet<>();//拦截器白名单
|
||||
|
||||
static {
|
||||
@@ -74,7 +72,7 @@ public class LoginInterceptor extends HandlerInterceptorAdapter {
|
||||
|
||||
private void getOutputStream(HttpServletResponse response, String msg) {
|
||||
try {
|
||||
logger.error(msg);
|
||||
log.error(msg);
|
||||
OutputStream outputStream = response.getOutputStream();
|
||||
RestMessage restMessage = new RestMessage();
|
||||
restMessage.setMessage(msg);
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.xwbing.handler;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.xwbing.configuration.DispatcherServletConfig;
|
||||
import com.xwbing.constant.CommonConstant;
|
||||
import com.xwbing.constant.CommonEnum;
|
||||
import com.xwbing.domain.entity.sys.SysAuthority;
|
||||
@@ -11,10 +10,9 @@ import com.xwbing.service.sys.SysUserService;
|
||||
import com.xwbing.util.CommonDataUtil;
|
||||
import com.xwbing.util.RestMessage;
|
||||
import com.xwbing.util.ThreadLocalUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
@@ -27,12 +25,12 @@ import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Slf4j
|
||||
public class UrlPermissionsInterceptor extends HandlerInterceptorAdapter {
|
||||
@Resource
|
||||
private SysAuthorityService sysAuthorityService;
|
||||
@Resource
|
||||
private SysUserService sysUserService;
|
||||
private final Logger logger = LoggerFactory.getLogger(DispatcherServletConfig.class);
|
||||
private static final Set<String> SET = new HashSet<>();//拦截器白名单
|
||||
|
||||
static {
|
||||
@@ -59,7 +57,7 @@ public class UrlPermissionsInterceptor extends HandlerInterceptorAdapter {
|
||||
return true;
|
||||
} else {
|
||||
try {
|
||||
logger.error("没有权限");
|
||||
log.error("没有权限");
|
||||
OutputStream outputStream = response.getOutputStream();
|
||||
RestMessage restMessage = new RestMessage();
|
||||
restMessage.setMessage("没有权限");
|
||||
@@ -109,7 +107,7 @@ public class UrlPermissionsInterceptor extends HandlerInterceptorAdapter {
|
||||
continue;
|
||||
}
|
||||
if (validateUrl.equalsIgnoreCase(perms)) {
|
||||
exit= true;
|
||||
exit = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,14 +2,13 @@ package com.xwbing.handler;
|
||||
|
||||
import com.xwbing.annotation.LogInfo;
|
||||
import com.xwbing.util.IpUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.aspectj.lang.JoinPoint;
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.annotation.AfterReturning;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.aspectj.lang.annotation.Before;
|
||||
import org.aspectj.lang.annotation.Pointcut;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.context.request.RequestContextHolder;
|
||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
@@ -28,10 +27,10 @@ import java.util.stream.Collectors;
|
||||
* 创建时间: 2017/5/10 16:34
|
||||
* 作者: xiangwb
|
||||
*/
|
||||
@Slf4j
|
||||
@Aspect
|
||||
@Component
|
||||
public class WebLogAspect {
|
||||
private final Logger logger = LoggerFactory.getLogger(WebLogAspect.class);
|
||||
private final ThreadLocal<Long> startTime = new ThreadLocal<>();
|
||||
|
||||
@Pointcut("within(com.xwbing.controller..*) && @annotation(logInfo)")
|
||||
@@ -67,7 +66,7 @@ public class WebLogAspect {
|
||||
if (args != null && args.length > 0) {
|
||||
params = Arrays.stream(args).filter(o -> !(o instanceof HttpServletRequest || o instanceof HttpServletResponse)).collect(Collectors.toList());
|
||||
}
|
||||
logger.info("{}/{}:{} started 参数:{}", targetName, methodName, info, params);
|
||||
log.info("{}/{}:{} started 参数:{}", targetName, methodName, info, params);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -82,7 +81,7 @@ public class WebLogAspect {
|
||||
String info = logInfo.value();
|
||||
String targetName = joinPoint.getTarget().getClass().getName();
|
||||
String methodName = joinPoint.getSignature().getName();
|
||||
logger.info("{}/{}:{} completed in {} ms", targetName, methodName, info, ms);
|
||||
log.info("{}/{}:{} completed in {} ms", targetName, methodName, info, ms);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -92,7 +91,7 @@ public class WebLogAspect {
|
||||
*/
|
||||
// @AfterThrowing(pointcut = "pointCut()", throwing = "e")
|
||||
public void afterThroing(Exception e) {
|
||||
logger.error("异常信息:{}", e.getMessage());
|
||||
log.error("异常信息:{}", e.getMessage());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -107,11 +106,11 @@ public class WebLogAspect {
|
||||
String info = logInfo.value();// 获取注解信息
|
||||
Object result = null;// 被代理对象方法返回的结果
|
||||
try {
|
||||
logger.info("{} start", info);
|
||||
log.info("{} start", info);
|
||||
result = pjp.proceed();
|
||||
logger.info("{} end", info);
|
||||
log.info("{} end", info);
|
||||
} catch (Throwable e) {
|
||||
logger.error(e.getMessage());
|
||||
log.error(e.getMessage());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user