dubbo+zookeeper+springmvc整合2(服务提供者实现)

上一遍已经讲到dubbo项目划分,现在基于项目划分实现服务提供者


1.dubbo包的导入(maven)


首先把问题提出来一下:本人现在使用的是jdk1.8,tomcat8可能运行项目时会出现component-scan包扫描错误提示了要用jdk1.7一下,原因是dubbo的com.alibaba包里面spring版本是2.0的4.x以上才能兼容jdk1.8所以可以吧jdk换成1.7在运行

2.provider配置

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
        http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd">

        <!-- 注解包扫描位置 -->
        <context:component-scan base-package="com.provider.impl" />

        <!-- 接入dubbo的应用程序名称 -->
        <dubbo:application name="demo-provider"/>

        <!-- 注册创库地址: zookeeper组件,192.168.61.128:2181 -->
        <dubbo:registry address="zookeeper://127.0.0.1:2181"/>

        <!-- 用dubbo协议在20880端口暴露服务 -->
        <dubbo:protocol name="dubbo" port="20880"/>

        <!-- 声明需要暴露的服务接口
          请注意ref属性中指定的HelloService接口实现类,它并没有在xml文件中定义,而是使用注解的方式在class中定义 -->
        <dubbo:service interface="com.provider.DemoService" ref="helloServiceImpl"></dubbo:service>
</beans>
3.添加一个测试接口

4.编写测试类用main方法运行测试

package com.test;

import org.springframework.context.support.ClassPathXmlApplicationContext;

public class ProviderApp {
    public static void main(String[] args) throws Exception {
        //读取配置文件
        new ClassPathXmlApplicationContext(new String[]{"dubbo-provider.xml"});
        System.out.println("provider服务已注册");
        //使线程阻塞
        System.in.read();
    }
}

5.打开dubbo主页查看服务

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值