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;
}
标签:String,Spring,流程,private,name,secretkey,public,accessKey,SDK
From: https://blog.csdn.net/ITboyxzx/article/details/142768669