一、所需jar包如下
<!--
dubbo
开始 -->
<
dependency
>
<
groupId
>com.alibaba
</
groupId
>
<
artifactId
>dubbo
</
artifactId
>
<
version
>2.6.0
</
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
>
</
dependency
>
<
dependency
>
<
groupId
>com.101tec
</
groupId
>
<
artifactId
>zkclient
</
artifactId
>
<
version
>0.7
</
version
>
</
dependency
>
<!--
dubbo
结束 -->
二 、配置成servlet方式,与web项目共用容器,contextpath为容器下war路径
<?
xml
version=
"1.0"
encoding=
"UTF-8"
?>
xsi:schemaLocation=
"http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://code.alibabatech.com/schema/dubbohttp://code.alibabatech.com/schema/dubbo/dubbo.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context.xsd"
>
<
dubbo:application
name=
"ft-billapplication"
logger=
"slf4j"
/>
<dubbo:registry address="
zookeeper://127.0.0.1:2181" timeout="3000" />
<
dubbo:protocol
name=
"dubbo"
port=
"20880"
/>
<
dubbo:protocol
name=
"rest"
port=
"8088"
contextpath=
"ft-my"
server=
"servlet"
/>
<
dubbo:service
interface=
"io.my.ft.bill.api.CreditCardStatementApi"
ref=
"creditStatementApi"
/>
<
dubbo:service
interface=
"io.my.ft.bill.api.CreditCardStatementQueryApi"
ref=
"creditStatementQueryApi"
/>
</
beans
>
2.1
web.xml配置
需要添加dubbo的listener与servlet,注意不要与spring mvc冲突,保证dubbo的listener与servlet优先于spring mvc加载!!!
dubbo依赖如下:
<
listener
>
<
listener-class
>com.alibaba.dubbo.remoting.http.servlet.BootstrapListener
</
listener-class
>
</
listener
>
<
servlet
>
<
servlet-name
>dubboDispatcher
</
servlet-name
>
<
servlet-class
>com.alibaba.dubbo.remoting.http.servlet.DispatcherServlet
</
servlet-class
>
<
load-on-startup
>1
</
load-on-startup
>
</
servlet
>
<
servlet-mapping
>
<
servlet-name
>dubboDispatcher
</
servlet-name
>
<
url-pattern
>/*
</
url-pattern
>
</
servlet-mapping
>
随后的spring mvc配置如下:
<
listener
>
<
listener-class
>org.springframework.web.context.ContextLoaderListener
</
listener-class
>
</
listener
>
<
servlet
>
<
servlet-name
>spring
</
servlet-name
>
<
servlet-class
>org.springframework.web.servlet.DispatcherServlet
</
servlet-class
>
<
init-
param
>
<
param-name
>contextConfigLocation
</
param-name
>
<
param-value
>
classpath*:
biz/spring-mvc.xml
</
param-value
>
</
init-
param
>
<
load-on-startup
>1
</
load-on-startup
>
</
servlet
>
<
servlet-mapping
>
<
servlet-name
>spring
</
servlet-name
>
<
url-pattern
>/clear/gen
</
url-pattern
>
<url-pattern>/ok.htm</url-pattern>
</
servlet-mapping
>
2.2 配置成servlet形式优点:与项目共用一个容器进程,缺点是:原项目中spring mvc的Controller层的http接口地址,静态资源需要在web.xml中一一列出在<url-pattern>/clear/gen</url-pattern>
三、配置成非servlet方式,dubbo的rest接口单独启动一套容器进程,与项目的web容器互不影响,与spring mvc没冲突
<?
xml
version=
"1.0"
encoding=
"UTF-8"
?>
xsi:schemaLocation=
"http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://code.alibabatech.com/schema/dubbohttp://code.alibabatech.com/schema/dubbo/dubbo.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context.xsd"
>
<
dubbo:application
name=
"ft-billapplication"
logger=
"slf4j"
/>
<dubbo:registry address="
zookeeper://127.0.0.1:2181" timeout="3000" />
<
dubbo:protocol
name=
"dubbo"
port=
"20880"
/>
<
dubbo:protocol
name=
"rest"
port=
"8088"
/>
<
dubbo:service
interface=
"io.my.ft.bill.api.CreditCardStatementApi"
ref=
"creditStatementApi"
/>
<
dubbo:service
interface=
"io.my.ft.bill.api.CreditCardStatementQueryApi"
ref=
"creditStatementQueryApi"
/>
</
beans
>
web.xml配置不必修改,不需要添加dubbo的listener与servlet