前言

解决方案

步骤

pom

服务提供者

		<dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>dubbo-rpc-rest</artifactId>
            <version>2.6.5</version>
        </dependency>
		<dependency>
            <groupId>com.alibaba.spring.boot</groupId>
            <artifactId>dubbo-spring-boot-starter</artifactId>
        </dependency>

api子模块

        <dependency>
		    <groupId>javax.ws.rs</groupId>
		    <artifactId>javax.ws.rs-api</artifactId>
		    <version>2.1.1</version>
		    <scope>provided</scope>
		</dependency>
		

springboot启动配置

spring:
  application:
    name: xxxxxxxx
  dubbo:
    server: true
    registry: zookeeper://127.0.0.1:2181
    consumer:
      timeout: 60000
    protocols:
        - name: dubbo
        - name: rest
          port: 8888
          server: tomcat
          contextpath: server

server类操作

  1. consumes是数据接收方式
  2. produces是数据返回方式
@Path("user")
@Consumes({MediaType.APPLICATION_JSON, MediaType.TEXT_XML})
public interface UserService {
    @GET
    @Path("get")
	void get();
}

所有的提供。

@Service(interfaceClass = UserService.class , protocol= {"dubbo","rest"})
@Transactional(rollbackFor = Exception.class)
public class UserServiceImpl implements UserService {
	public  void get(){
	}
}

结语

04-25 01:24