Cloud Native 5 min read

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.

Java Architecture Diary
Java Architecture Diary
Java Architecture Diary
Integrate Tencent Polaris Service Discovery with Spring Cloud 2022 on Java 17

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.

Polaris dashboard
Polaris dashboard

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

Polaris console
Polaris console

Service Registration – Provider

Add Spring Cloud Tencent 3.0 adaptation dependency

<code>&lt;dependency&gt;
  &lt;groupId&gt;com.tencent.cloud&lt;/groupId&gt;
  &lt;artifactId&gt;spring-cloud-starter-tencent-polaris-discovery&lt;/artifactId&gt;
&lt;/dependency&gt;

&lt;dependencyManagement&gt;
  &lt;dependencies&gt;
    &lt;dependency&gt;
      &lt;groupId&gt;com.tencent.cloud&lt;/groupId&gt;
      &lt;artifactId&gt;spring-cloud-tencent-dependencies&lt;/artifactId&gt;
      &lt;version&gt;1.8.1-2022.0.0-RC2&lt;/version&gt;
      &lt;type&gt;pom&lt;/type&gt;
      &lt;scope&gt;import&lt;/scope&gt;
    &lt;/dependency&gt;
  &lt;/dependencies&gt;
&lt;/dependencyManagement&gt;</code>

Configure

application.yaml

to 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.yaml

to 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>
microservicesservice discoverySpring CloudPolarisjava-17Spring Boot 3
Java Architecture Diary
Written by

Java Architecture Diary

Committed to sharing original, high‑quality technical articles; no fluff or promotional content.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.