Dubbo——小例子的实现——提供方的实现

接上文

--------------------------------------------------------------------------------------------------------------------------------

步骤:

1、创建maven工程:

pom.xml文件内容同上文,只不过将tomcat的端口号改下;

2、编写web.xml文件:

同上文

3、将上文创建的interface,连同他的包一同复制在我们的src/main/java下

4、创建class作为我们的handler

说明:1、@RestController注解相当于@Controller和@ResponseBody的合体

         2、@Reference注解为alibaba的,是远程调用标签

package com.aynu.dubbo.handler;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import com.alibaba.dubbo.config.annotation.Reference;
import com.aynu.dubbo.service.IDubboTest;

@RestController
@RequestMapping("/test")
public class DubboHanlder {

	@Reference
	private IDubboTest service;
	
	@RequestMapping("/dubbo.do")
	public void dubbo() {
		String DUBBO = service.sayHello("DUBBO");
		System.out.println(DUBBO);
	}
}

5、创建spring-handler.xml文件:

<?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:mvc="http://www.springframework.org/schema/mvc"
	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://www.springframework.org/schema/mvc
        http://www.springframework.org/schema/mvc/spring-mvc.xsd
        http://code.alibabatech.com/schema/dubbo 
        http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
        
        <!-- 注册mvc解析器 -->
        <mvc:annotation-driven/>
        <!-- 为当前应用取名字,可以随意,建议为项目名 -->
        <dubbo:application name="dubbo_sonmer"/>
        <!-- 连接远程zookeeper -->
        <dubbo:registry address="zookeeper://192.168.146.128:2181"/>
        <!-- dubbo包扫描器 -->
        <dubbo:annotation package="com.aynu.dubbo.handler"/>
</beans>

6、运行(前提是提供方已经运行):

打开管控台,在消费者中可见内容:


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值