SpringBoot整合Dubbo2.6.7使用resteasy和netty实现rest风格的服务

1、添加依赖jar

       <dependency>
            <groupId>jakarta.servlet</groupId>
            <artifactId>jakarta.servlet-api</artifactId>
        </dependency>

        <!--使用resteasy netty发布rest服务 -->
        <dependency>
            <groupId>org.jboss.resteasy</groupId>
            <artifactId>resteasy-netty4</artifactId>
            <version>3.9.3.Final</version>
            <exclusions>
                <exclusion>
                    <artifactId>httpclient</artifactId>
                    <groupId>org.apache.httpcomponents</groupId>
                </exclusion>
            </exclusions>
        </dependency>

        <!--估计是消费端使用,demo仅仅展示服务端 -->
        <!--<dependency>
            <groupId>org.jboss.resteasy</groupId>
            <artifactId>resteasy-client</artifactId>
            <version>3.9.3.Final</version>
        </dependency>-->

        <dependency>
            <groupId>org.jboss.resteasy</groupId>
            <artifactId>resteasy-jackson2-provider</artifactId>
            <version>3.9.3.Final</version>
        </dependency>

2、编写服务接口

public interface DemoService {

    UserInfo test();

}

3、编写服务实现

@Path("/aa")
@Service(protocol = {"dubbo", "rest"})
public class DemoServiceImpl implements DemoService {

    private AtomicInteger atomicInteger = new AtomicInteger();

    @GET
    @Path("/aa")
    @Consumes({MediaType.APPLICATION_JSON})
    @Produces({MediaType.APPLICATION_JSON})
    @Override
    public UserInfo retry() {
        log.info("retry()重试请求 start: ");
        atomicInteger.getAndAdd(1);

        UserInfo userInfo = new UserInfo();
        userInfo.setUserName("retry");
        userInfo.setAge(atomicInteger.get());

        return userInfo;
    }

}

4 SpringBoot application.properties中添加配置

#dubbo协议配置
dubbo.protocols.dubbo.name=dubbo
dubbo.protocols.dubbo.port=20880
#rest协议配置
dubbo.protocols.rest.name=rest
dubbo.protocols.rest.port=20980
dubbo.protocols.rest.server=netty

5 浏览器访问

http://localhost:20980/aa/aa

6 本文主要是为了记录dubbo如何使用resteasy和netty发布rest服务

源码地址:https://download.csdn.net/download/u013202238/13120786

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值