Spring SDK创建和使用完整流程

SDK创建篇

1.spring项目创建

2.导入yml文件输入配置信息提示所需要的依赖

3.移除pom文件不必要的信息

 4.移除启动类

5.编写对外提供的客户端类


public class TestClient {
   
    private String accessKey;

    private String secretkey;

    public TestClient(String accessKey, String secretkey) {
        this.accessKey = accessKey;
        this.secretkey = secretkey;
    }

    public void logInfo(String name){
        System.out.println(name + ":use sdk ["+accessKey+"]  ["+secretkey+"]");
    }

}

6.编写获取yml文件配置信息的配置类

@Data
@ComponentScan
@Configuration
@ConfigurationProperties("xzx.client")
public class XzxClientConfig {

    private String accessKey;

    private String secretkey;

    @Bean
    public TestClient testClient(){
        return new TestClient(accessKey,secretkey);
    }


}

7.在resources目录下创建MATA-INF目录并在下面创建spring.factories文件

 

org.springframework.boot.autoconfigure.EnableAutoConfiguration=cn.com.xzx.xzxsdk.XzxClientConfig

8.打包并下载我们的项目为jar包

注意:如果需要给外部使用,可以将jar上传到maven中央仓库中

SDK使用篇

1.引入依赖

2. 编写yml文件配置(创建SDK时候Config类)

xzx:
  client:
    access-key: 
    secretkey: 

3.依赖注入并调用对外提供的接口

    @Resource
    private TestClient testClient;


    @RequestMapping("/hello")
    @ResponseBody
    public String hello(@RequestParam(name = "name", defaultValue = "unknown user") String name) {
        testClient.logInfo("hello.word");
        return "Hello " + name;
    }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值