{"record":{"id":"cf0e1f91b2d928b8","repo":"alibaba/spring-cloud-alibaba","slug":"type-method-attribute-exists-but-type-class-at","errorCode":null,"errorMessage":"{type} method attribute exists but {type} class attribute is not exists in bean[{beanName}]","messagePattern":"(.+?) method attribute exists but (.+?) class attribute is not exists in bean\\[(.+?)\\]","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-sentinel/src/main/java/com/alibaba/cloud/sentinel/custom/SentinelBeanPostProcessor.java","lineNumber":124,"sourceCode":"\t}\n\n\tprivate void checkBlock4RestTemplate(Class<?> blockClass, String blockMethod,\n\t\t\tString beanName, String type) {\n\t\tif (blockClass == void.class && !StringUtils.hasLength(blockMethod)) {\n\t\t\treturn;\n\t\t}\n\t\tif (blockClass != void.class && !StringUtils.hasLength(blockMethod)) {\n\t\t\tlog.error(\n\t\t\t\t\t\"{} class attribute exists but {} method attribute is not exists in bean[{}]\",\n\t\t\t\t\ttype, type, beanName);\n\t\t\tthrow new IllegalArgumentException(type + \" class attribute exists but \"\n\t\t\t\t\t+ type + \" method attribute is not exists in bean[\" + beanName + \"]\");\n\t\t}\n\t\telse if (blockClass == void.class && StringUtils.hasLength(blockMethod)) {\n\t\t\tlog.error(\n\t\t\t\t\t\"{} method attribute exists but {} class attribute is not exists in bean[{}]\",\n\t\t\t\t\ttype, type, beanName);\n\t\t\tthrow new IllegalArgumentException(type + \" method attribute exists but \"\n\t\t\t\t\t+ type + \" class attribute is not exists in bean[\" + beanName + \"]\");\n\t\t}\n\t\tClass[] args;\n\t\tif (type.equals(SentinelConstants.URLCLEANER_TYPE)) {\n\t\t\targs = new Class[] {String.class};\n\t\t}\n\t\telse {\n\t\t\targs = new Class[] {HttpRequest.class, byte[].class,\n\t\t\t\t\tClientHttpRequestExecution.class, BlockException.class};\n\t\t}\n\t\tString argsStr = Arrays.toString(\n\t\t\t\tArrays.stream(args).map(clazz -> clazz.getSimpleName()).toArray());\n\t\tMethod foundMethod = ClassUtils.getStaticMethod(blockClass, blockMethod, args);\n\t\tif (foundMethod == null) {\n\t\t\tlog.error(\n\t\t\t\t\t\"{} static method can not be found in bean[{}]. The right method signature is {}#{}{}, please check your class name, method name and arguments\",\n\t\t\t\t\ttype, beanName, blockClass.getName(), blockMethod, argsStr);\n\t\t\tthrow new IllegalArgumentException(type","sourceCodeStart":106,"sourceCodeEnd":142,"githubUrl":"https://github.com/alibaba/spring-cloud-alibaba/blob/115d5901102009492e05d5ec18c3f79cad4077d0/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-sentinel/src/main/java/com/alibaba/cloud/sentinel/custom/SentinelBeanPostProcessor.java#L106-L142","documentation":"The mirror of error 103: a method-name attribute is supplied for a RestTemplate Sentinel handler (block/fallback/urlCleaner) but the corresponding class attribute is empty. Because the handler is resolved as a static method on a named class, a method without a class cannot be located, so Sentinel refuses the configuration at bean post-processing time.","triggerScenarios":"Configuring spring.cloud.sentinel.resttemplate.block-method=handleBlock with no block-class, or @SentinelRestTemplate(blockMethod = \"handleBlock\") and no blockClass.","commonSituations":"Removing or commenting out the class line while keeping the method line. Copying a partial config snippet from documentation.","solutions":["Add the matching class attribute, e.g. spring.cloud.sentinel.resttemplate.block-class=com.example.MyBlock.","If you did not mean to configure this handler, remove the method attribute so both are unset.","Verify the class is on the classpath and visible to the bean post-processor."],"exampleFix":"// before\n@SentinelRestTemplate(blockMethod = \"handleBlock\")\n// after\n@SentinelRestTemplate(blockClass = MyBlock.class, blockMethod = \"handleBlock\")","handlingStrategy":"validation","validationCode":"void validateHandler(Class<?> clazz, String method) {\n  boolean hasClass = clazz != null && clazz != void.class;\n  boolean hasMethod = method != null && !method.isBlank();\n  if (hasClass != hasMethod) throw new IllegalStateException(\"class and method attributes must both be set or both be empty\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never supply a -method without its -class.","Keep paired handler properties adjacent in config files.","Run a config-validation test in CI."],"tags":["sentinel","resttemplate","config-validation","startup"],"backgroundTag":null,"analyzedSha":"115d5901102009492e05d5ec18c3f79cad4077d0","analyzedAt":"2026-08-14T04:47:13.900Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}