dubbo(二)发布dubbo服务

来源:互联网 发布:户外拍摄技巧淘宝 编辑:程序博客网 时间:2024/05/22 01:52

1.pom.xml中添加相关jar包

<!-- dubbo相关jar包 --><dependency><groupId>com.alibaba</groupId><artifactId>dubbo</artifactId></dependency><dependency><groupId>org.apache.zookeeper</groupId><artifactId>zookeeper</artifactId></dependency><dependency><groupId>com.github.sgroschupf</groupId><artifactId>zkclient</artifactId></dependency>


2.配置spring的配置文件中添加dubbo相关配置:

发布dubbo服务相关配置:

<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans"xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p"xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"xmlns:dubbo="http://code.alibabatech.com/schema/dubbo" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsdhttp://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.2.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.2.xsdhttp://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsdhttp://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.2.xsd"><!-- 配置包扫描器,扫描所有带@Service注解的类 --><context:component-scan base-package="com.milan.service"/><!-- 发布dubbo服务 --><!-- 提供方应用信息,用于计算依赖关系 --><dubbo:application name="dubbo-demo" /><!-- 注册中心的地址 --><dubbo:registry protocol="zookeeper" address="192.168.1.1:2181" /><!-- 用dubbo协议在20880端口暴露服务 --><dubbo:protocol name="dubbo" port="20880" /><!-- 声明需要暴露的服务接口 --><dubbo:service interface="com.milan.service.ItemService" ref="itemServiceImpl" timeout="300000"/></beans>

引用dubbo服务相关配置:

<?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:p="http://www.springframework.org/schema/p"xmlns:context="http://www.springframework.org/schema/context"xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"xmlns:mvc="http://www.springframework.org/schema/mvc"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd        http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd"><!-- 配置注解驱动 --><mvc:annotation-driven /><!-- 视图解析器 --><beanclass="org.springframework.web.servlet.view.InternalResourceViewResolver"><property name="prefix" value="/WEB-INF/jsp/" /><property name="suffix" value=".jsp" /></bean><!-- 配置包扫描器,扫描@Controller注解的类 --><context:component-scan base-package="com.milan.controller"/><!-- 配置资源映射 --><mvc:resources location="/css/" mapping="/css/**"/><mvc:resources location="/js/" mapping="/js/**"/><!-- 引用dubbo服务 --><dubbo:application name="dubbo-demo"/><dubbo:registry protocol="zookeeper" address="192.168.1.1:2181"/><dubbo:reference interface="com.milan.service.ItemService" id="itemService" /></beans>      

3.启动dubbo相关

启动zookeeper

./zkServer.sh start

关闭Linux防火墙

service iptables stop







阅读全文
0 0
原创粉丝点击