Dubbo和Java chassis底层都使用了Spring的依赖注入和bean管理系统,所以使用Dubbo的服务迁移到ServiceComb工作量较小, 主要改动在依赖和配置方面。
服务提供方
替换依赖
将对dubbo的依赖替换为对Java chassis的依赖
Dubbo
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>dubbo</artifactId>
<version>${dubbo.version}</version>
</dependency>
Java chassis
<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.servicecomb</groupId>
<artifactId>java-chassis-dependencies</artifactId>
<version>${java.chassis.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>io.servicecomb</groupId>
<artifactId>transport-highway</artifactId>
</dependency>
<dependency>
<groupId>io.servicecomb</groupId>
<artifactId>transport-rest-vertx</artifactId>
</dependency>
<dependency>
<groupId>io.servicecomb</groupId>
<artifactId>provider-pojo</artifactId>
</dependency>
</dependencies>
替换服务接口注释
以 @Service
注释方式暴露的服务接口,用 @RpcSchema
替代
Dubbo
import com.alibaba.dubbo.config.annotation.Service;
@Service
public class SomeServiceImpl implements SomeService {
// ...
}
Java chassis
@RpcSchema(schemaId = "someServiceEndpoint")
public class SomeServiceImpl implements SomeService {
// ...
}
修改提供方启动入口
Dubbo
public class ProviderMain
{