alibaba/spring-cloud-alibaba · error · IllegalArgumentException

{type} static method can not be found in bean[{beanName}]. T

Error message

{type} static method can not be found in bean[{beanName}]. The right method signature is {blockClass}#{blockMethod}{argsStr}, please check your class name, method name and arguments

What it means

After class and method are both provided, Sentinel uses Spring's ClassUtils.getStaticMethod to locate a public static method with the exact argument signature the framework expects. For urlCleaner it is (String); for block/fallback it is (HttpRequest, byte[], ClientHttpRequestExecution, BlockException). If no such static method exists on the class, this IllegalArgumentException is thrown with the required signature embedded in the message.

Source

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

			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(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");
		}

		Class<?> standardReturnType;
		if (type.equals(SentinelConstants.URLCLEANER_TYPE)) {
			standardReturnType = String.class;
		}
		else {
			standardReturnType = ClientHttpResponse.class;
		}

		if (!standardReturnType.isAssignableFrom(foundMethod.getReturnType())) {
			log.error("{} method return value in bean[{}] is not {}: {}#{}{}", type,
					beanName, standardReturnType.getName(), blockClass.getName(),
					blockMethod, argsStr);

View on GitHub (pinned to 115d590110)

Solutions

  1. Make the method public static with the exact signature shown in the error's argsStr.
  2. For urlCleaner use 'public static String clean(String url)'; for block/fallback use 'public static ClientHttpResponse handle(HttpRequest, byte[], ClientHttpRequestExecution, BlockException)'.
  3. Confirm the method name in the attribute matches the declared name exactly (case-sensitive).
  4. Ensure the class is the one referenced by the -class attribute, not a subclass.

Example fix

// before
public ClientHttpResponse handle(HttpRequest req, byte[] body, ClientHttpRequestExecution exec, BlockException ex) { ... }
// after
public static ClientHttpResponse handle(HttpRequest req, byte[] body, ClientHttpRequestExecution exec, BlockException ex) { ... }
Defensive patterns

Strategy: validation

Validate before calling

void requireStaticHandler(Class<?> c, String name, Class<?>... args) throws NoSuchMethodException {
  java.lang.reflect.Method m = c.getMethod(name, args);
  if (!java.lang.reflect.Modifier.isStatic(m.getModifiers()))
    throw new IllegalStateException(name + " must be static with signature " + Arrays.toString(args));
}

Type guard

static boolean isStaticHandler(Class<?> c, String name, Class<?>... args) {
  try { return java.lang.reflect.Modifier.isStatic(c.getMethod(name, args).getModifiers()); }
  catch (NoSuchMethodException e) { return false; }
}

Prevention

When it happens

Trigger: Naming a method that does not exist, is not static, or has the wrong parameters, e.g. an instance method handleBlock(HttpRequest,byte[],ClientHttpRequestExecution,BlockException) or a static method with only (BlockException). Mismatching the urlCleaner signature (String) with a block-style signature also triggers it.

Common situations: Renaming the handler method after wiring it. Marking the method non-static. Copying a block handler as a urlCleaner without changing its parameters.

Related errors


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