spring MVC中Dubbo的配置

1、服务提供方的bubbo配置:

<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:aop="http://www.springframework.org/schema/aop"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:task="http://www.springframework.org/schema/task"
    xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
        http://www.springframework.org/schema/mvc
        http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context-4.0.xsd
        http://www.springframework.org/schema/aop
        http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
        http://www.springframework.org/schema/tx
        http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
        http://www.springframework.org/schema/task
           http://www.springframework.org/schema/task/spring-task-4.0.xsd
        http://code.alibabatech.com/schema/dubbo
        http://code.alibabatech.com/schema/dubbo/dubbo.xsd">

    <!-- 配置Dubbo提供方 -->
    <!-- 配置提供方的名称即服务名 -->
    <dubbo:application name="babasport-service-product"/>

    <!-- 配置注册中心 -->
    <!-- 配置集群的zookeeper机器,address中间用逗号隔开,端口号在zookeeper的config文件中查看;protocol:协议为zookeeper
       <dubbo:registry address="192.168.1.1:2181,192.168.1.2:2182" protocol="zookeeper"/> -->
    <dubbo:registry address="192.168.1.110:2181" protocol="zookeeper"/> 

    <!-- 设置端口号(服务提供方的), 若不设置则默认是20880 -->
    <dubbo:protocol port="20880" name="dubbo"/>

    <!-- 暴露的接口 -->
    <dubbo:service interface="cn.itcast.core.service.TestTbService" ref="testTbService"/>

</beans>
        

2、服务的消费方配置:

<?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:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:task="http://www.springframework.org/schema/task" xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
        http://www.springframework.org/schema/mvc
        http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context-4.0.xsd
        http://www.springframework.org/schema/aop
        http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
        http://www.springframework.org/schema/tx
        http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
        http://www.springframework.org/schema/task
           http://www.springframework.org/schema/task/spring-task-4.0.xsd
        http://code.alibabatech.com/schema/dubbo
        http://code.alibabatech.com/schema/dubbo/dubbo.xsd">

    <!-- Dubbo的消费方,消费方的名称 -->
    <dubbo:application name="babasport-console"/>

    <!-- 注册中心 -->
    <dubbo:registry address="192.168.1.110:2181" protocol="zookeeper"/>

    <!-- 获取接口及实现类 -->
    <dubbo:reference interface="cn.itcast.core.service.TestTbService" id="testTbService"/> 

</beans>

注意:

使用Dubbo传递参数,该参数需要实现序列化。

时间: 2024-08-03 20:21:34

spring MVC中Dubbo的配置的相关文章

spring mvc 中web.xml配置信息解释

在项目中总会遇到一些关于加载的优先级问题,近期也同样遇到过类似的,所以自己查找资料总结了下,下面有些是转载其他人的,毕竟人家写的不错,自己也就不重复造轮子了,只是略加点了自己的修饰. 首先可以肯定的是,加载顺序与它们在 web.xml 文件中的先后顺序无关.即不会因为 filter 写在 listener 的前面而会先加载 filter.最终得出的结论是:listener -> filter -> servlet 同时还存在着这样一种配置节:context-param,它用于向 Servlet

spring mvc中应用@ResponseBody的配置

在spring的配置文件中添加json转换器即可 <!-- spring mvc中@ResponseBody对象转json --> <bean class ="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" > <property name="messageConverters"> <list> <ref

Spring MVC中处理静态资源的多种方法

处理静态资源,我想这可能是框架搭建完成之后Web开发的”头等大事“了. 因为一个网站的显示肯定会依赖各种资源:脚本.图片等,那么问题来了,如何在页面中请求这些静态资源呢? 还记得Spring MVC中的DispatcherServlet吗?它是Spring MVC中的前置控制器,若配置的拦截路径为“/”,那么所有的请求都将被它拦截.对静态资源的访问也属于一个请求,那么也会被它拦截,然后进入它的匹配流 程,我们知道它是根据HandlerMapping的配置来匹配的.而对于静态资源来说,默认的Spr

Spring MVC中一般类使用service

在Spring MVC中,Controller中使用service只需使用注解@Resource就行,但是一般类(即不使用@Controller注解的类)要用到service时,可用如下方法: 1.SpringContextUtil package com.test.framework.utils; import org.springframework.beans.BeansException; import org.springframework.beans.factory.NoSuchBea

spring mvc中的文件上传

使用commons-fileupload上传文件所需要的架包有:commons-fileupload 和common-io两个架包支持,可以到Apache官网下砸. 在配置文件spring-mvc.xml中配置上传: <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"> //文件上传最大是多少 <

Spring MVC中基于注解的 Controller

终于来到了基于注解的 Spring MVC 了.之前我们所讲到的 handler,需要根据 url 并通过 HandlerMapping 来映射出相应的 handler 并调用相应的方法以响应请求.实际上,ControllerClassNameHandlerMapping, MultiActionController 和选择恰当的 methodNameResolver(如 InternalPathMethodNameResolver) 就已经可以在很大程度上帮助我们省去不少的 XML 配置,谁让

Spring MVC 中的 forward 和 redirect

Spring MVC 中的 forward 和 redirect Spring MVC 中,我们在返回逻辑视图时,框架会通过 viewResolver 来解析得到具体的 View,然后向浏览器渲染.假设逻辑视图名为 hello,通过配置,我们配置某个 ViewResolver 如下: <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <description

(转)Spring MVC中处理静态资源的多种方法

处理静态资源,我想这可能是框架搭建完成之后Web开发的”头等大事“了. 因为一个网站的显示肯定会依赖各种资源:脚本.图片等,那么问题来了,如何在页面中请求这些静态资源呢? 还记得Spring MVC中的DispatcherServlet吗?它是Spring MVC中的前置控制器,若配置的拦截路径为“/”,那么所有的请求都将被它拦截.对静态资源的访问也属于一个请求,那么也会被它拦截,然后进入它的匹配流 程,我们知道它是根据HandlerMapping的配置来匹配的.而对于静态资源来说,默认的Spr

Spring MVC中数据绑定之日期类型

数据绑定应该算是Spring MVC的特点之一吧~简单易用且功能强大,极大地简化了我们编程人员对于用户输入数据的接收及转换. 早先版本的Spring中的数据绑定完全都是基于PropertyEditor的.而Spring3中引入了Converter,用来替代PropertyEditor完成类型转换. 那么我们也依照这个顺序,先来讲讲基于传统的PropertyEditor来实现日期类型的数据绑定. 在Spring MVC中,我们可以通过WebDataBinder来注册自定义的PropertyEdit