已有maven+spring+spring mvc项目,集成dubbo

来源:互联网 发布:mac 微信截图隐藏窗口 编辑:程序博客网 时间:2024/06/11 00:35

第一步:需要三个jar包:

<dependency>
<groupId>com.alibaba</groupId>
<artifactId>dubbo</artifactId>
<version>2.8.4</version>
<exclusions>
<exclusion>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.zookeeper</groupId>
<artifactId>zookeeper</artifactId>
<version>3.4.6</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</exclusion>
<exclusion>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
</exclusion>
</exclusions>
</dependency>

 PS:exclusions,根据自己情况使用

第二步:

创建dubbo配置文件xxx-xx.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:dubbo="http://code.alibabatech.com/schema/dubbo"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd">


<!-- 创建权益账户 -->
<!-- <dubbo:reference id="createCustService" interface="com.vivebest.internet.banking.core.ci.cust.service.CreateCustService"/> -->
<dubbo:application name="renren-web" owner="programmer" organization="dubbox"/>
<dubbo:registry address="${dubbo.registry.address}"/>
<!-- 在dubbo的配置文件中指定服务启动的绑定Ip dubbo.protocol.host 与dns有关-->
    <dubbo:protocol name="dubbo" port="${dubbo.protocol.port}"/>
<dubbo:reference id="xxx" interface="com.xxx.internet.xxx.common.service.xxxx"/>
</beans>

两步就ok了。

中间遇到的问题:

spring -mvc 文件中引入.properties文件

<context:property-placeholder location="classpath*:*.properties" />


原创粉丝点击