Solon

::forest-solon-plugin

</> markdown

此插件,由社区成员(夜の孤城)贡献

<dependency>
    <groupId>com.dtflys.forest</groupId>
    <artifactId>forest-solon-plugin</artifactId>
    <version>1.5.36</version>
</dependency>

1、描述

分布式扩展插件。基于 forest (代码仓库 )框架适配的 声明式 http 客户端插件。更多信息可见:框架官网

2、使用示例

使用 "@ForestClient" 声明接口(这是必须的):

//声明接口
@ForestClient
public interface MyClient {

    @Get("http://localhost:8080/hello")
    String helloForest();

}

声明接口的应用:

//测试
@Component
public class MyService {
    
    // 注入自定义的 Forest 接口实例
    @Inject
    private MyClient myClient;

    public void testClient() {
        // 调用自定义的 Forest 接口方法
        // 等价于发送 HTTP 请求,请求地址和参数即为 helloForest 方法上注解所标识的内容
        String result = myClient.helloForest();
        // result 即为 HTTP 请求响应后返回的字符串类型数据
        System.out.println(result);
    }
}