✅Test: 在 Lark 中使用天气服务

This commit is contained in:
2025-10-29 16:24:06 +08:00
parent 060466b7b7
commit e7ce159ec4
4 changed files with 52 additions and 5 deletions
+6
View File
@@ -33,6 +33,12 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<dependency>
<groupId>cn.hezhaohui</groupId>
<artifactId>common</artifactId>
@@ -1,12 +1,10 @@
package cn.hezhaohui.lark.client;
import cn.hezhaohui.entity.Weather;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
@FeignClient(name = "service-weather")
import cn.hezhaohui.entity.Weather;
public interface WeatherClient {
@GetMapping("get")
Weather getWeather();
}
@@ -0,0 +1,21 @@
package cn.hezhaohui.lark.client.impl;
import cn.hezhaohui.entity.Weather;
import cn.hezhaohui.lark.client.WeatherClient;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONUtil;
import org.springframework.stereotype.Component;
@Component
public class WeatherClientImpl implements WeatherClient {
@Override
public Weather getWeather() {
String ans = HttpUtil.get("http://localhost:8083/get");
Weather weather = JSONUtil.toBean(ans, Weather.class);
return weather;
}
}
@@ -0,0 +1,22 @@
package cn.hezhaohui.lark.client.impl;
import cn.hezhaohui.entity.Weather;
import cn.hezhaohui.lark.client.WeatherClient;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
@Slf4j
class WeatherClientImplTest {
@Resource
private WeatherClient weatherClient;
@Test
void getWeather() {
Weather weather = weatherClient.getWeather();
log.info(weather.toString());
}
}