tencent cloud

Service Registry and Governance

Spring Cloud Integration

PDF
포커스 모드
폰트 크기
마지막 업데이트 시간: 2026-05-07 18:12:22

Scenarios

This document provides a full-process demonstration of integrating a Spring Cloud application with the PolarisMesh governance center hosted by the Microservices Engine through a demo, helping you quickly learn how to use PolarisMesh.

Prerequisite

PolarisMesh service instances have been created. See create a PolarisMesh governance center.
Download the Github demo source code to your local machine and extract it.
The local build environment has the Java JDK and Maven installed and can access the Maven Central Repository.
Based on your own business, resources for business deployment have been prepared. You can choose one of the methods: virtual machine deployment or containerized deployment.
VM deployment The CVM instance has been created. For details, see Creating a CVM Instance.
Containerized deployment The TKE container cluster has been created. For details, see Creating a TKE Cluster.

Operation Steps

2. Select Polaris (Polaris) in the left sidebar, go to the PolarisMesh service instance engine list page, then click the target instance to go to the instance information page.
3. On the Engine Management - Instance Information page, view the access IP address. Spring Cloud applications access using the gRPC port (8091):



4. Modify the registry center IP address in the demo.
4.1 In the downloaded local demo source code directory, locate the following two files: spring-cloud-tencent-examples/polaris-discovery-example/discovery-callee-service/src/main/resources/bootstrap.yml and spring-cloud-tencent-examples/polaris-discovery-example/discovery-caller-service/src/main/resources/bootstrap.yml.
4.2 Add the Microservices Engine PolarisMesh grid IP address to the project configuration file (taking spring-cloud-tencent-examples/polaris-discovery-example/discovery-callee-service/src/main/resources/bootstrap.yml as an example).
server:
port: 0
spring:
application:
name: DiscoveryCallerService
cloud:
polaris:
enabled: true
address: grpc://{Polaris engine private network IP address}:8091
5. Package the demo source code into a Jar file.
5.1 Under the root directory of the polaris-discovery-example source code, open a command prompt and execute the command `mvn clean package` to package and compile the project.
5.2 After successful compilation, two Jar packages are generated as shown in the following table.
Software Package Directory
Software Package Name
Description
polaris-discovery-example/discovery-callee-service/target
discovery-callee-service-${version}-SNAPSHOT.jar
Service Provider
polaris-discovery-example/discovery-caller-service/target
discovery-caller-service-${version}-SNAPSHOT.jar
Service Consumer
6. Deploy the provider and consumer microservices applications. Choose one deployment method based on your actual business needs from VM deployment, containerized deployment, and TEM deployment.
6.1 VM deployment
Upload the Jar package to the Cloud Virtual Machine (CVM) instance.
Run the start command to launch:
nohup java -Djava.security.egd=file:/dev/./urandom -jar [jar package name] &
6.2 Containerized deployment
Write the dockerfile to build the image. Refer to:
FROM java:8
ADD ddiscovery-caller-service-${version}-SNAPSHOT.jar /root/app.jar
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/root/app.jar"]
Deploy and run the image via TKE
7. Verify the deployment results.
7.1 Go to the PolarisMesh service instance page mentioned earlier.
Choose Service Management > Service List to view the number of instances for the DiscoveryCallerService and DiscoveryCalleeService microservices:
If the number of instances is not zero, it indicates that the microservices engine has been successfully connected.
If the number of instances is zero, or if the service names DiscoveryCallerService and DiscoveryCalleeService are not found, it indicates that the microservice application failed to connect to the microservice engine.

7.2 Invoke the HTTP interface of the consumer. Execute the HTTP call, where ${app.port} is replaced with the listening port of the consumer, and ${add.address} is replaced with the exposed IP address of the consumer:
curl -L -X GET 'http://${add.address}:${app.port}/echo?value="hello-world'
Expected return value: hello-world


도움말 및 지원

문제 해결에 도움이 되었나요?

피드백