如何使用
2025/7/10小于 1 分钟
如何使用
1. 引入依赖
在项目中添加组件依赖
<dependency>
<groupId>top.codelong</groupId>
<artifactId>server-find-sdk</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
2. 配置属性
在application.yml
中添加配置:
server:
port: 777
gateway-server:
serverName: test-provider
center-addr: 127.0.0.1:18080
safeKey: safeKey
safeSecret: safeSecret
spring:
data:
redis:
database: 0
host: localhost
port: 6379
3. 添加注解
在服务实现类上添加@ApiInterface
:
@ApiInterface(interfaceName = "测试接口")
@Service
public class TestServiceImpl implements TestService {
}
在服务方法上添加@ApiMethod
:
@ApiInterface(interfaceName = "测试接口")
@Service
public class TestServiceImpl implements TestService {
@ApiMethod(isAuth = 0, isHttp = 0, httpType = HttpTypeEnum.GET, url = "test")
public String test(String name) {
return "hello world";
}
@ApiMethod(isAuth = 0, isHttp = 1, httpType = HttpTypeEnum.GET, url = "test2")
public String test2(String name) {
return "";
}
}
4. 启动应用
组件会自动:
- 扫描并注册带注解的服务
- 暴露Dubbo服务
- 启动心跳监听