WebConfig.java 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package com.jeesite.modules.config;
  2. import com.jeesite.common.config.Global;
  3. import com.jeesite.common.lang.StringUtils;
  4. import com.jeesite.modules.interceptor.MesClientAccessLogInterceptor;
  5. import com.jeesite.modules.interceptor.SiteClosedInterceptor;
  6. import com.jeesite.modules.sys.log.LogJsonResultSupport;
  7. import org.springframework.beans.factory.annotation.Autowired;
  8. import org.springframework.context.annotation.Configuration;
  9. import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
  10. import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
  11. import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
  12. @Configuration
  13. public class WebConfig implements WebMvcConfigurer {
  14. @Autowired
  15. private SiteClosedInterceptor siteClosedInterceptor;
  16. @Autowired
  17. private LogJsonResultSupport logJsonResultSupport;
  18. @Autowired
  19. private MesClientAccessLogInterceptor mesClientAccessLogInterceptor;
  20. @Override
  21. public void addInterceptors(InterceptorRegistry registry) {
  22. registry.addInterceptor(siteClosedInterceptor);
  23. registry.addInterceptor(logJsonResultSupport).addPathPatterns("/**/sys/log/form");
  24. applyLogPaths(registry.addInterceptor(mesClientAccessLogInterceptor));
  25. }
  26. private void applyLogPaths(InterceptorRegistration registration) {
  27. String add = Global.getProperty("web.interceptor.log.addPathPatterns");
  28. String exclude = Global.getProperty("web.interceptor.log.excludePathPatterns");
  29. if (StringUtils.isBlank(add)) {
  30. registration.addPathPatterns("/a/**");
  31. } else {
  32. for (String p : StringUtils.split(add, ",")) {
  33. if (StringUtils.isNotBlank(p)) {
  34. registration.addPathPatterns(p.trim());
  35. }
  36. }
  37. }
  38. if (StringUtils.isNotBlank(exclude)) {
  39. for (String p : StringUtils.split(exclude, ",")) {
  40. if (StringUtils.isNotBlank(p)) {
  41. registration.excludePathPatterns(p.trim());
  42. }
  43. }
  44. }
  45. }
  46. }