alibaba/spring-cloud-alibaba · error · IllegalArgumentException

{type} class attribute exists but {type} method attribute is

Error message

{type} class attribute exists but {type} method attribute is not exists in bean[{beanName}]

What it means

SentinelBeanPostProcessor validates RestTemplate-level Sentinel configuration for block/fallback/urlCleaner handlers. Each handler is specified by a pair of attributes: a class (blockClass/fallbackClass/urlCleanerClass) and a method name. This IllegalArgumentException fires when a class attribute is present but the matching method-name attribute is empty/missing. It is a configuration-time error that aborts bean post-processing at startup.

Source

Thrown at spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-sentinel/src/main/java/com/alibaba/cloud/sentinel/custom/SentinelBeanPostProcessor.java:117

				SentinelConstants.BLOCK_TYPE);
		checkBlock4RestTemplate(sentinelRestTemplate.fallbackClass(),
				sentinelRestTemplate.fallback(), beanName,
				SentinelConstants.FALLBACK_TYPE);
		checkBlock4RestTemplate(sentinelRestTemplate.urlCleanerClass(),
				sentinelRestTemplate.urlCleaner(), beanName,
				SentinelConstants.URLCLEANER_TYPE);
	}

	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(

View on GitHub (pinned to 115d590110)

Solutions

  1. Add the matching method attribute, e.g. spring.cloud.sentinel.resttemplate.block-method=handleBlock, or blockMethod = "handleBlock".
  2. If you intended class-only config, remove the class attribute so both are treated as unset (the method returns early when both are empty).
  3. Ensure the method name exists on the referenced class and is a public static method with the documented signature.

Example fix

// before
@SentinelRestTemplate(blockClass = MyBlock.class)
// 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

When it happens

Trigger: Annotating or configuring a RestTemplate Sentinel handler with only the class, e.g. spring.cloud.sentinel.resttemplate.block-class=com.example.MyBlock without a block-method property, or @SentinelRestTemplate(blockClass = MyBlock.class) with no blockMethod.

Common situations: Copying a working handler but deleting the method line. Renaming the method attribute and forgetting to keep it. Assuming the class alone exposes a default handler method.

Related errors


AI-assisted analysis of alibaba/spring-cloud-alibaba@115d590110 (2026-08-14). Data as JSON: /api/errors/64e8c9b35c36b675. Report an issue: GitHub.