1. Framework version
Spring Boot、 Spring Cloud 、 Spring Cloud Alibaba
Frame Name | Framework version |
---|---|
Spring Boot | 2.2. |
Spring Cloud | Hoxton.SR3 |
Spring Cloud Alibaba | 2.2. |
2. Source code display
Remote authenticationController
Controller code snippet
@RestController @Slf4j @RequestMapping("/security") public class AuthenticationController { @Resource private AuthenticationService authenticationService; @PostMapping("/auth") public Boolean checkAuth(@RequestBody @Valid BaseRequest baseRequest) { ("<-------------------------->"); return (baseRequest); } }
Gateway referenceOpenFeign
rely
<!-- OpenFeign --> <dependency> <groupId></groupId> <artifactId>spring-cloud-starter-openfeign</artifactId> <version>2.2.</version> </dependency>
GatewayOpenFeign
Calling the client
@Component @FeignClient(value = "rms-security-service") public interface InvokeSecurityServiceClient { @PostMapping("/security/auth") Boolean checkAuth(BaseRequest baseRequest); }
III. Problem description
In the process of unified authentication and authentication at the gateway level, the interface of the authentication server needs to be remotely called for authentication operations.
But in adoptionOpenFiegn
During the remote call process, the following error report stack appears, resulting in the remote call failure.
- Stack Information
: No qualifying bean of type '' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@(required=true)}
at $(:384)
Suppressed: $OnAssemblyException:
Error has been observed at the following site(s):
|_ checkpoint ⇢ [DefaultWebFilterChain]
|_ checkpoint ⇢ [DefaultWebFilterChain]
|_ checkpoint ⇢ [DefaultWebFilterChain]
|_ checkpoint ⇢ [DefaultWebFilterChain]
|_ checkpoint ⇢ [DefaultWebFilterChain]
|_ checkpoint ⇢ [DefaultWebFilterChain]
|_ checkpoint ⇢ [DefaultWebFilterChain]
|_ checkpoint ⇢ $$Lambda$772/0x0000016c006c3040 [DefaultWebFilterChain]
|_ checkpoint ⇢ [DefaultWebFilterChain]
|_ checkpoint ⇢ $ServerWebExchangeReactorContextWebFilter [DefaultWebFilterChain]
|_ checkpoint ⇢ [DefaultWebFilterChain]
|_ checkpoint ⇢ [DefaultWebFilterChain]
|_ checkpoint ⇢ HTTP GET "/open-platform/achievement/list?page=1" [ExceptionHandlingWebHandler]
Stack trace:
- Key information
No qualifying bean of type '
4. Solution
Stack Analysis
-
HttpMessageConverters
Not injected into the container to manage -
ISSUES
track -
Click hereCheck
issues
information
Solution
Source code:No exception was found in the
AutoConfiguration
Open
@Configuration(proxyBeanMethods = false) @ConditionalOnClass() @Conditional() @AutoConfigureAfter({ , , }) @Import({ , , }) public class HttpMessageConvertersAutoConfiguration { }
Source code:@Conditional()
@Conditional
yesSpring4
The newly provided annotation is to make judgments according to certain conditions and register the container with the conditions.bean
Check the class againNotReactiveWebApplicationCondition
static class NotReactiveWebApplicationCondition extends NoneNestedConditions { NotReactiveWebApplicationCondition() { super(ConfigurationPhase.PARSE_CONFIGURATION); } @ConditionalOnWebApplication(type = ) private static class ReactiveWebApplication { } }
Spring Cloud Gateway
It is based onWebFlux
YesReactiveWeb
,soHttpMessageConverters
Not automatically injected.
So I copied the source code directly in the configuration fileBean
, and finally succeed.
# Create a new configuration class@Configuration public class WebFluxWithOpenFeignConfig { @Bean @ConditionalOnMissingBean public HttpMessageConverters messageConverters(ObjectProvider<HttpMessageConverter<?>> converters) { return new HttpMessageConverters(().collect(())); } }
Summarize
The above is personal experience. I hope you can give you a reference and I hope you can support me more.