tencent cloud

Service Registry and Governance

Register and discovery

PDF
Focus Mode
Font Size
Last updated: 2026-05-07 18:12:22

Scenarios

This document describes how to develop a Java application locally, access a Polaris (North Star) instance via Spring Cloud, and implement service registration and discovery.

Prerequisite

1. Before starting development, please ensure you have downloaded and installed Java and Maven.
2. A Polaris (North Star) instance has been created. For detailed steps, see Engine Management.

Operation Steps

For your convenience in quick access, we have prepared a Demo application for you. Click to download.

Step 1: Add Dependencies for Service Registration and Discovery

1. Add the spring cloud tencent Dependency

Modify the pom.xml in the application's root directory to add dependencyManagement:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.tencent.cloud</groupId>
<artifactId>spring-cloud-tencent-dependencies</artifactId>
<version>${version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
Note:
Please choose based on the versions of Spring Boot and Spring Framework in your project, and select the appropriate Spring Cloud Tencent version.

2. Add the spring cloud tencent starter

Method 1: Introduce all sct starters via spring-cloud-starter-tencent-all.
<dependency>
<groupId>com.tencent.cloud</groupId>
<artifactId>spring-cloud-starter-tencent-all</artifactId>
</dependency>
Method 2: Introduce both spring-cloud-starter-tencent-polaris-discovery and spring-cloud-starter-tencent-polaris-router.
<dependency>
<groupId>com.tencent.cloud</groupId>
<artifactId>spring-cloud-starter-tencent-polaris-discovery</artifactId>
</dependency>

<dependency>
<groupId>com.tencent.cloud</groupId>
<artifactId>spring-cloud-starter-tencent-polaris-router</artifactId>
</dependency>

Step 2: Add Polaris Configuration File

1. Create an application.yml file in the project's main/resources directory.
2. Configure the application name, Polaris (North Star) server IP address, and other information in the application.yml file. For detailed information on the server IP address, refer to: Engine Management > Client Access Address.
spring:
application:
name: ${application.name}
cloud:
polaris:
enabled: true
address: grpc://${replace with the Polaris service address}:8091
namespace: default

Step 3: Start the Application

After the application successfully starts, go to the Polaris console to view the service registration information, as shown in the figure below:

image



Step 4: Service Invocation

In Spring Cloud, you can use RestTemplate or Feign to initiate service calls.
RestTemplate
Simply annotate with @LoadBalanced at the location where you instantiate RestTemplate.
@Bean
@LoadBalanced
public RestTemplate restTemplate() {
return new RestTemplate();
}
Feign
Through the Feign framework, simply follow the standard Feign approach for invocation.

Help and Support

Was this page helpful?

Help us improve! Rate your documentation experience in 5 mins.

Feedback