标签:wired group ice 空间 throw rgs manage turn autowired
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Hoxton.SR4</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-alibaba-dependencies</artifactId>
<version>2.2.1.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
spring:
profiles:
active: default
application:
name: user-center
cloud:
nacos:
discovery:
server-addr: localhost:8848
# namespace 值为nacos上配置的命名空间ID
# namespace: b7c0175d-f64c-45ab-8bb9-0981b4aceae9
# 集群
# cluster-name: beijing
# 元数据配置
metadata:
hello: hi
@Slf4j
@RestController
@RequestMapping("/share")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class ShareController {
private final ShareService shareService;
private final RestTemplate restTemplate;
private final DiscoveryClient discoveryClient;
@GetMapping("/{id}")
public ShareDto findById(@PathVariable Integer id){
Share share = shareService.findById(id);
List<ServiceInstance> instances = discoveryClient.getInstances("user-center");
String url = instances.stream()
.map(instance->instance.getUri()+"/user/{id}")
.findFirst()
.orElseThrow(()->new IllegalArgumentException("当前没有实例!"));
UserDto userDto = restTemplate.getForObject(
url,
UserDto.class,
share.getId());
log.info("请求的目标地址{}",url);
ShareDto shareDto = new ShareDto();
BeanUtils.copyProperties(share,shareDto);
shareDto.setWxNickname(userDto.getWxNickname());
return shareDto;
}
}
标签:wired group ice 空间 throw rgs manage turn autowired
原文地址:https://www.cnblogs.com/fly-book/p/12818017.html