首页 > 解决方案 > 查找和 DI 定义一个具体的 org.springframework.web.reactive.function.client.WebClient

问题描述

如何注册以下接口的具体实现(通过 applicationcontext.xml)(xml 配置)?

org.springframework.web.reactive.function.client.WebClient

“指定的类是一个接口”

https://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/web/reactive/function/client/WebClient.html

public interface WebClient

完整代码

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.reactive.function.client.WebClient;

import javax.inject.Inject;

public class MyClientProxy implements IMyClientProxy {

    private final WebClient webClient;

    private static Logger LOGGER;


    public MyClientProxy(Logger lgr, WebClient webClient) {
        if (null == lgr) {
            throw new IllegalArgumentException("Logger is null");
        }
        this.LOGGER = lgr;

        if (null == webClient) {
            throw new IllegalArgumentException("WebClient is null");
        }
        this.webClient = webClient;
    }
}
    

进口

// https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-webflux
compile group: 'org.springframework.boot', name: 'spring-boot-starter-webflux', version: '2.3.1.RELEASE'

显然,这是行不通的

(来自 applicationcontext.xml)

    <bean id="zzzWebClientBean"
          class="org.springframework.web.reactive.function.client.WebClient">
    </bean>

但在“我尝试过的”类别中......

标签: javaspringjava-8java-11

解决方案


好的,这是一个工厂静态方法。

    <bean id="zzzWebClientBean"
          class="org.springframework.web.reactive.function.client.WebClient" factory-method="create">
    </bean>

推荐阅读