Commit bf898edfc8cbaeb5228af50ac6d4d541533c31be

Authored by shaofan
1 parent f80ead1f

添加默认全局异常处理条件

在IdempotentAutoConfiguration类中,增加一个条件注解@ConditionalOnProperty,该注解的作用是当spring.idempotent.default-exception-handler的值为真时,这个配置类才会启动。同时,在IdempotentProperties类中添加了一个新的属性defaultExceptionHandler,该属性默认为真。
src/main/java/com/diligrp/idempotent/spring/boot/IdempotentAutoConfiguration.java
... ... @@ -40,6 +40,7 @@ public class IdempotentAutoConfiguration {
40 40 @ControllerAdvice
41 41 @Order(value = Ordered.LOWEST_PRECEDENCE - 100)
42 42 @Controller
  43 + @ConditionalOnProperty(prefix = "spring.idempotent", value = "default-exception-handler", havingValue = "true", matchIfMissing = true)
43 44 public static class IdempotentExceptionConfiguration {
44 45  
45 46 private static final Logger logger = LoggerFactory.getLogger(IdempotentExceptionConfiguration.class);
... ...
src/main/java/com/diligrp/idempotent/spring/boot/IdempotentProperties.java
... ... @@ -40,6 +40,11 @@ public class IdempotentProperties {
40 40 */
41 41 private Boolean manualSettingIdempotentInterceptor = false;
42 42  
  43 + /**
  44 + * 默认全局异常处理
  45 + */
  46 + private Boolean defaultExceptionHandler = true;
  47 +
43 48  
44 49 public void setIdempotentInterceptorOrderValue(Integer idempotentInterceptorOrderValue) {
45 50 this.idempotentInterceptorOrderValue = idempotentInterceptorOrderValue;
... ... @@ -93,4 +98,12 @@ public class IdempotentProperties {
93 98 public void setIdempotentInterceptorOrderValue(int idempotentInterceptorOrderValue) {
94 99 this.idempotentInterceptorOrderValue = idempotentInterceptorOrderValue;
95 100 }
  101 +
  102 + public Boolean getDefaultExceptionHandler() {
  103 + return defaultExceptionHandler;
  104 + }
  105 +
  106 + public void setDefaultExceptionHandler(Boolean defaultExceptionHandler) {
  107 + this.defaultExceptionHandler = defaultExceptionHandler;
  108 + }
96 109 }
... ...