Updated on 2023-11-08 GMT+08:00

Access to a ServiceComb Engine

To use Spring Cloud Huawei to access ServiceComb engines, perform the following steps:

  1. Add or modify component dependencies.
  2. Add the CSE ServiceComb engine configuration to the configuration file boostrap.yaml.

For details, see Connecting Spring Cloud Applications to CSE ServiceComb Engines. This section describes the precautions during the reconstruction, especially the precautions related to component dependency.

Assume that the original service systems are all Maven-based projects.

Step 1: Get Familiar with the POM Structure of the Original Service System

The POM structure of the Spring Cloud application system is classified into the following types:

  • The first method is to use the public POM provided by Spring Boot or Spring Cloud as the parent. For example:
    <parent>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-parent</artifactId>
      <version>2.3.5.RELEASE</version>
    </parent>

    Alternatively, ensure that the following dependencies are introduced to the project:

    <parent>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-build</artifactId>
      <version>2.2.3.RELEASE</version>
    </parent>
  • The second method is to use the parent of the project instead of the public POM provided by Spring Boot or Spring Cloud as the parent. However, dependency management is introduced into the project. For example:
    <dependencyManagement>
      <dependencies>
        <dependency>
          <groupId>org.springframework.cloud</groupId>
          <artifactId>spring-cloud-dependencies</artifactId>
          <version>${spring-cloud.version}</version>
          <type>pom</type>
          <scope>import</scope>
        </dependency>
      </dependencies>
    </dependencyManagement>
  • Some application systems use both the first and second methods. They use the public POM provided by Spring Boot or Spring Cloud as the parent, and introduce dependency management.

Step 2: Modify Parent and Dependency Management to Avoid Conflicts with Third-Party Software

Modifying parent and dependency management is a key step to prevent third-party software conflicts.

  1. Determine the Spring Cloud Huawei version, and then query the Spring Boot version and Spring Cloud version corresponding to the Spring Cloud Huawei version. You are advised to use the latest version of Spring Cloud Huawei. You can query the mapping Spring Boot version and Spring Cloud version on the official Spring Cloud Huawei website.
  2. Compare the parent version of the current project with the Spring Boot version and Spring Cloud version that match Spring Cloud Huawei. If the parent version of the current project is earlier, change it to the Spring Cloud Huawei version. Otherwise, no modification is required.
  3. Independently introduce the dependency management of Spring Boot, Spring Cloud, and Spring Cloud Huawei to the dependency management of the current project. If the Spring Boot or Spring Cloud of the original project is of a later version, use the version of the original project. Otherwise, use the Spring Cloud Huawei version. Pay attention to the sequence of dependency management. The dependency management in the front will be used first. Spring Boot and Spring Cloud versions are the basis. You are advised not to provide additional dependency management for the software managed by the two dependencies. You can follow the community version to effectively reduce conflicts. The three dependencies are introduced separately to facilitate the upgrade of a component.
    <dependencyManagement>
        <dependencies>
          <!-- configure user spring cloud / spring boot versions -->
          <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-dependencies</artifactId>
            <version>${spring-boot.version}</version>
            <type>pom</type>
            <scope>import</scope>
          </dependency>
          <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-dependencies</artifactId>
            <version>${spring-cloud.version}</version>
            <type>pom</type>
            <scope>import</scope>
          </dependency>
          <!-- configure spring cloud huawei version -->
          <dependency>
            <groupId>com.huaweicloud</groupId>
            <artifactId>spring-cloud-huawei-bom</artifactId>
            <version>${spring-cloud-huawei.version}</version>
            <type>pom</type>
            <scope>import</scope>
          </dependency>
        </dependencies>  
    </dependencyManagement>
    If the service system integrates dependencies such as Spring Cloud Alibaba, delete the dependencies from dependency management. You are advised to delete unnecessary dependencies that have been managed by Spring Boot and Spring Cloud. Common dependencies that need to be deleted are as follows:
    <dependencyManagement>
      <dependencies>
        <!-- Dependency of third-party extension -->
        <dependency>
          <groupId>com.alibaba.cloud</groupId>
          <artifactId>spring-cloud-alibaba-dependencies</artifactId>
          <version>2.1.0.RELEASE</version>
          <type>pom</type>
          <scope>import</scope>
          </dependency>
          <!-- Dependency managed by Spring Cloud -->
          <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-feign</artifactId>
            <version>1.4.7.RELEASE</version>
          </dependency>
        </dependencies>
    </dependencyManagement>

Step 3: Add or Delete Dependencies

The components related to service registration and discovery, centralized configuration management, and service governance are added. The third-party implementations of the components are deleted. Other components do not need to be changed. However, after Spring Boot and Spring Cloud are upgraded, these components may need to be upgraded accordingly. Compatibility issues are usually found in the compilation phase or service startup phase.

Generally, you do not need to specify the version number when adding a dependency. The version number is managed by the parent and dependency management.

Introduce the following in microservice applications:

<dependency>
  <groupId>com.huaweicloud</groupId>
  <artifactId>spring-cloud-starter-huawei-service-engine</artifactId>
</dependency>

Introduce the following to the Spring Cloud Gateway application:

<dependency>
  <groupId>com.huaweicloud</groupId>
  <artifactId>spring-cloud-starter-huawei-service-engine-gateway</artifactId>
</dependency>

If the following dependencies exist, delete them:

<!-- Nacos scenario-->
<dependency>
  <groupId>com.alibaba.cloud</groupId>
  <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
</dependency>
<dependency>
  <groupId>com.alibaba.cloud</groupId>
  <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
<dependency>
  <groupId>com.alibaba.cloud</groupId>
  <artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
</dependency>
<dependency>
  <groupId>com.alibaba.csp</groupId>
  <artifactId>spring-cloud-gateway-starter-ahas-sentinel</artifactId>
</dependency>
<dependency>
  <groupId>com.alibaba.csp</groupId>
  <artifactId>spring-boot-starter-ahas-sentinel-client</artifactId>
</dependency>

<!-- Eureka scenario -->
<dependency>
  <groupId>org.springframework.cloud</groupId>
  <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency>
  <groupId>org.springframework.cloud</groupId>
  <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>

Generally, the following dependencies do not need to be deleted:

<dependency>
  <groupId>com.alibaba</groupId>
  <artifactId>druid</artifactId>
  <version>1.0.28</version>
</dependency>