Class SpringBeanParameterResolver
- All Implemented Interfaces:
ParameterResolver<Object>
Autowired
from the Spring application context.
This resolver allows dependency injection of Spring-managed beans directly into handler methods. It supports both
type-based and Qualifier
-based resolution, and will prioritize beans marked as @Primary
.
If no bean can be resolved unambiguously (e.g., multiple candidates and no qualifier or primary), the parameter is not injected and a warning is logged.
Example:
@HandleCommand
public void handle(MyCommand command, @Autowired MyService myService) {
myService.performAction();
}
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected UnaryOperator
<Object> boolean
matches
(Parameter parameter, Annotation methodAnnotation, Object value) Indicates whether the resolved value is compatible with the declared parameter type.resolve
(Parameter p, Annotation methodAnnotation) Resolves aParameter
of a handler method into a value function based on the given message.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface io.fluxcapacitor.common.handling.ParameterResolver
determinesSpecificity, filterMessage
-
Constructor Details
-
SpringBeanParameterResolver
public SpringBeanParameterResolver()
-
-
Method Details
-
resolve
Description copied from interface:ParameterResolver
Resolves aParameter
of a handler method into a value function based on the given message.If the parameter cannot be resolved by this resolver and
ParameterResolver.matches(java.lang.reflect.Parameter, java.lang.annotation.Annotation, M)
is not implemented, this method must returnnull
.- Specified by:
resolve
in interfaceParameterResolver<Object>
- Parameters:
p
- the parameter to resolvemethodAnnotation
- the annotation present on the handler method (e.g.,@HandleEvent
)- Returns:
- a function that takes a message and returns a value to be injected into the method parameter, or
null
if the parameter cannot be resolved andParameterResolver.matches(java.lang.reflect.Parameter, java.lang.annotation.Annotation, M)
is not implemented.
-
matches
Description copied from interface:ParameterResolver
Indicates whether the resolved value is compatible with the declared parameter type.This method helps determine whether the parameter can be injected for a given message. It first invokes
ParameterResolver.resolve(java.lang.reflect.Parameter, java.lang.annotation.Annotation)
and then verifies that the returned value (if any) is assignable to the parameter type.- Specified by:
matches
in interfaceParameterResolver<Object>
- Parameters:
parameter
- the parameter being checkedmethodAnnotation
- the annotation on the handler methodvalue
- the message instance to use for resolution- Returns:
true
if the parameter can be resolved and assigned to,false
otherwise
-
computeParameterResolver
-