Integrate Tencent Polaris Service Discovery with Spring Cloud 2022 on Java 17
This guide shows how to install Tencent Polaris, configure Spring Cloud Tencent 3.0 dependencies, register services with Spring Boot 3.0, and consume them via declarative HTTP clients, providing a complete Java 17 microservice discovery solution.
We anticipate that the combination of Java 17, Spring Framework 6.0, Spring Boot 3.0 and Spring Cloud 2022 will soon become mainstream, so Spring Cloud Tencent quickly adapted to Spring Cloud 2022 + Spring Boot 3.0.
Installation of Polaris
Polaris is Tencent’s open‑source service discovery and governance center, aiming to solve visibility, fault tolerance, traffic control and security in distributed or microservice architectures.
<code>docker run -d -p 15010:15010 -p 8080:8080 -p 8090:8090 -p 8091:8091 -p 8093:8093 -p 8761:8761 -p 9000:9000 -p 9090:9090 polarismesh/polaris-server-standalone:latest</code>Access the console at http://127.0.0.1:8080
Service Registration – Provider
Add Spring Cloud Tencent 3.0 adaptation dependency
<code><dependency>
<groupId>com.tencent.cloud</groupId>
<artifactId>spring-cloud-starter-tencent-polaris-discovery</artifactId>
</dependency>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.tencent.cloud</groupId>
<artifactId>spring-cloud-tencent-dependencies</artifactId>
<version>1.8.1-2022.0.0-RC2</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement></code>Configure
application.yamlto connect to Polaris
<code>spring:
cloud:
polaris:
address: grpc://127.0.0.1:8091</code>Expose a service interface
<code>@RestController
@RequestMapping
public class ProviderController {
@GetMapping("/provider/{name}")
public String provider(@PathVariable String name) {
return name;
}
}</code>Service Registration – Consumer
Add Spring Cloud Tencent 3.0 adaptation dependency
Configure
application.yamlto connect to Polaris (same as provider)
Write an HTTP interface for remote calls
<code>@HttpExchange
public interface DemoRemoteApi {
@GetExchange("/provider/{name}")
Mono<String> provider(@PathVariable String name);
}</code>Register the HTTP interface client
<code>@Bean
DemoRemoteApi demoApi(ReactorLoadBalancerExchangeFilterFunction lbFunction) {
WebClient webClient = WebClient.builder()
.filter(lbFunction)
.baseUrl("http://provider")
.build();
HttpServiceProxyFactory factory = HttpServiceProxyFactory.builder(WebClientAdapter.forClient(webClient)).build();
return factory.createClient(DemoRemoteApi.class);
}</code>Consume the remote service
<code>@RestController
@RequestMapping
public class ConsumerController {
@Autowired
private DemoRemoteApi demoRemoteApi;
@GetMapping("/consumer2")
public Mono<String> consumer2() {
return demoRemoteApi.provider("xzcxz");
}
}</code>Java Architecture Diary
Committed to sharing original, high‑quality technical articles; no fluff or promotional content.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.