alibaba/spring-cloud-alibaba · error · IllegalArgumentException
{type} method attribute exists but {type} class attribute is
Error message
{type} method attribute exists but {type} class attribute is not exists in bean[{beanName}] What it means
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.
Source
Thrown at spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-sentinel/src/main/java/com/alibaba/cloud/sentinel/custom/SentinelBeanPostProcessor.java:124
}
private void checkBlock4RestTemplate(Class<?> blockClass, String blockMethod,
String beanName, String type) {
if (blockClass == void.class && !StringUtils.hasLength(blockMethod)) {
return;
}
if (blockClass != void.class && !StringUtils.hasLength(blockMethod)) {
log.error(
"{} class attribute exists but {} method attribute is not exists in bean[{}]",
type, type, beanName);
throw new IllegalArgumentException(type + " class attribute exists but "
+ type + " method attribute is not exists in bean[" + beanName + "]");
}
else if (blockClass == void.class && StringUtils.hasLength(blockMethod)) {
log.error(
"{} method attribute exists but {} class attribute is not exists in bean[{}]",
type, type, beanName);
throw new IllegalArgumentException(type + " method attribute exists but "
+ type + " class attribute is not exists in bean[" + beanName + "]");
}
Class[] args;
if (type.equals(SentinelConstants.URLCLEANER_TYPE)) {
args = new Class[] {String.class};
}
else {
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) {
log.error(
"{} 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(typeView on GitHub (pinned to 115d590110)
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.
Example fix
// before @SentinelRestTemplate(blockMethod = "handleBlock") // after @SentinelRestTemplate(blockClass = MyBlock.class, blockMethod = "handleBlock")
Defensive patterns
Strategy: validation
Validate before calling
void validateHandler(Class<?> clazz, String method) {
boolean hasClass = clazz != null && clazz != void.class;
boolean hasMethod = method != null && !method.isBlank();
if (hasClass != hasMethod) throw new IllegalStateException("class and method attributes must both be set or both be empty");
} Prevention
- Never supply a -method without its -class.
- Keep paired handler properties adjacent in config files.
- Run a config-validation test in CI.
When it happens
Trigger: Configuring spring.cloud.sentinel.resttemplate.block-method=handleBlock with no block-class, or @SentinelRestTemplate(blockMethod = "handleBlock") and no blockClass.
Common situations: Removing or commenting out the class line while keeping the method line. Copying a partial config snippet from documentation.
Related errors
- {type} class attribute exists but {type} method attribute is
- {type} static method can not be found in bean[{beanName}]. T
- {type} method return value in bean[{beanName}] is not {stand
- [Sentinel Starter] DataSource {dataSourceName}dataType is cu
- [Sentinel Starter] DataSource {dataSourceName} dataType: {pr
AI-assisted analysis of alibaba/spring-cloud-alibaba@115d590110 (2026-08-14).
Data as JSON: /api/errors/cf0e1f91b2d928b8.
Report an issue: GitHub.