| 
16 | 16 | 
 
  | 
17 | 17 | package org.springframework.cloud.gateway.server.mvc.config;  | 
18 | 18 | 
 
  | 
 | 19 | +import java.lang.reflect.Modifier;  | 
19 | 20 | import java.util.ArrayList;  | 
20 | 21 | import java.util.Arrays;  | 
21 | 22 | import java.util.Collections;  | 
 | 
30 | 31 | import java.util.function.Consumer;  | 
31 | 32 | import java.util.function.Function;  | 
32 | 33 | 
 
  | 
 | 34 | +import jakarta.annotation.Nullable;  | 
33 | 35 | import org.apache.commons.logging.Log;  | 
34 | 36 | import org.apache.commons.logging.LogFactory;  | 
35 | 37 | 
 
  | 
36 | 38 | import org.springframework.beans.factory.BeanFactory;  | 
37 | 39 | import org.springframework.beans.factory.BeanNotOfRequiredTypeException;  | 
38 | 40 | import org.springframework.beans.factory.NoSuchBeanDefinitionException;  | 
 | 41 | +import org.springframework.beans.factory.NoUniqueBeanDefinitionException;  | 
39 | 42 | import org.springframework.beans.factory.config.ConfigurableBeanFactory;  | 
40 | 43 | import org.springframework.boot.context.properties.bind.Bindable;  | 
41 | 44 | import org.springframework.boot.context.properties.bind.Binder;  | 
@@ -351,12 +354,38 @@ private <T> T invokeOperation(OperationMethod operationMethod, Map<String, Objec  | 
351 | 354 | 		else {  | 
352 | 355 | 			args.putAll(operationArgs);  | 
353 | 356 | 		}  | 
354 |  | -		ReflectiveOperationInvoker operationInvoker = new ReflectiveOperationInvoker(operationMethod,  | 
355 |  | -				this.parameterValueMapper);  | 
 | 357 | + | 
 | 358 | +		ReflectiveOperationInvoker operationInvoker = new ReflectiveOperationInvoker(  | 
 | 359 | +				resolveInvocationTargetBean(operationMethod), operationMethod, this.parameterValueMapper);  | 
356 | 360 | 		InvocationContext context = new InvocationContext(args, trueNullOperationArgumentResolver);  | 
357 | 361 | 		return operationInvoker.invoke(context);  | 
358 | 362 | 	}  | 
359 | 363 | 
 
  | 
 | 364 | +	@Nullable  | 
 | 365 | +	private Object resolveInvocationTargetBean(OperationMethod operationMethod) {  | 
 | 366 | +		// if the method is static, we don't have to find the invocation target bean  | 
 | 367 | +		if (Modifier.isStatic(operationMethod.getMethod().getModifiers())) {  | 
 | 368 | +			return null;  | 
 | 369 | +		}  | 
 | 370 | + | 
 | 371 | +		try {  | 
 | 372 | +			if (beanFactory != null) {  | 
 | 373 | +				return beanFactory.getBean(operationMethod.getMethod().getDeclaringClass());  | 
 | 374 | +			}  | 
 | 375 | +		}  | 
 | 376 | +		catch (NoUniqueBeanDefinitionException e) {  | 
 | 377 | +			log.warn(LogMessage.format(  | 
 | 378 | +					"Multiple beans found for type [%s], this non-static operation method [%s] will be invoked without bean context",  | 
 | 379 | +					operationMethod.getMethod().getDeclaringClass().getName(), operationMethod.getMethod().getName()));  | 
 | 380 | +		}  | 
 | 381 | +		catch (NoSuchBeanDefinitionException e) {  | 
 | 382 | +			log.debug(LogMessage.format(  | 
 | 383 | +					"No bean registered for type [%s], this non-static operation method [%s] will be invoked without bean context",  | 
 | 384 | +					operationMethod.getMethod().getDeclaringClass().getName(), operationMethod.getMethod().getName()));  | 
 | 385 | +		}  | 
 | 386 | +		return null;  | 
 | 387 | +	}  | 
 | 388 | + | 
360 | 389 | 	private Object bindConfigurable(OperationMethod operationMethod, Map<String, Object> args,  | 
361 | 390 | 			OperationParameter operationParameter) {  | 
362 | 391 | 		Class<?> configurableType = operationParameter.getType();  | 
 | 
0 commit comments