From b059e1f8e3cdeae8b05de679e9132509e20375a3 Mon Sep 17 00:00:00 2001 From: fangjian0423 Date: Tue, 15 Jan 2019 21:59:25 +0800 Subject: [PATCH] refactor log information --- .../custom/SentinelBeanPostProcessor.java | 33 +++++++++++-------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/spring-cloud-alibaba-sentinel/src/main/java/org/springframework/cloud/alibaba/sentinel/custom/SentinelBeanPostProcessor.java b/spring-cloud-alibaba-sentinel/src/main/java/org/springframework/cloud/alibaba/sentinel/custom/SentinelBeanPostProcessor.java index 20823674..18580aa5 100644 --- a/spring-cloud-alibaba-sentinel/src/main/java/org/springframework/cloud/alibaba/sentinel/custom/SentinelBeanPostProcessor.java +++ b/spring-cloud-alibaba-sentinel/src/main/java/org/springframework/cloud/alibaba/sentinel/custom/SentinelBeanPostProcessor.java @@ -99,36 +99,41 @@ public class SentinelBeanPostProcessor implements MergedBeanDefinitionPostProces } if (blockClass != void.class && StringUtils.isEmpty(blockMethod)) { logger.error( - "{} class property exists but {}" - + " method property is not exists in bean[{}]", + "{} class attribute exists but {} method attribute is not exists in bean[{}]", type, type, beanName); - System.exit(-1); + throw new IllegalArgumentException(type + " class attribute exists but " + + type + " method attribute is not exists in bean[" + beanName + "]"); } else if (blockClass == void.class && !StringUtils.isEmpty(blockMethod)) { logger.error( - "{} method property exists but {} class property is not exists in bean[{}]", + "{} method attribute exists but {} class attribute is not exists in bean[{}]", type, type, beanName); - System.exit(-1); + throw new IllegalArgumentException(type + " method attribute exists but " + + type + " class attribute is not exists in bean[" + beanName + "]"); } Class[] args = new Class[] { HttpRequest.class, byte[].class, ClientHttpRequestExecution.class, BlockException.class }; + String argsStr = Arrays.toString( + Arrays.stream(args).map(clazz -> clazz.getSimpleName()).toArray()); Method foundMethod = ClassUtils.getStaticMethod(blockClass, blockMethod, args); if (foundMethod == null) { logger.error( - "{} method can not be found in bean[{}]. The right method signature is {}#{}{}, please check your class name, method name and arguments", - type, beanName, blockClass.getName(), blockMethod, - Arrays.toString(Arrays.stream(args) - .map(clazz -> clazz.getSimpleName()).toArray())); - System.exit(-1); + "{} static method can not be found in bean[{}]. The right method signature is {}#{}{}, please check your class name, method name and arguments", + type, beanName, blockClass.getName(), blockMethod, argsStr); + throw new IllegalArgumentException(type + + " static method can not be found in bean[" + beanName + + "]. The right method signature is " + blockClass.getName() + "#" + + blockMethod + argsStr + + ", please check your class name, method name and arguments"); } if (!ClientHttpResponse.class.isAssignableFrom(foundMethod.getReturnType())) { logger.error( "{} method return value in bean[{}] is not ClientHttpResponse: {}#{}{}", - type, beanName, blockClass.getName(), blockMethod, - Arrays.toString(Arrays.stream(args) - .map(clazz -> clazz.getSimpleName()).toArray())); - System.exit(-1); + type, beanName, blockClass.getName(), blockMethod, argsStr); + throw new IllegalArgumentException(type + " method return value in bean[" + + beanName + "] is not ClientHttpResponse: " + blockClass.getName() + + "#" + blockMethod + argsStr); } if (type.equals(SentinelConstants.BLOCK_TYPE)) { BlockClassRegistry.updateBlockHandlerFor(blockClass, blockMethod,