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"
xmlns:context=
"http://www.springframework.org/schema/context"
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: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.htmurl-pattern>
servlet-mapping
>
2.2 配置成servlet形式优点:与项目共用一个容器进程,缺点是:原项目中spring mvc的Controller层的http接口地址,静态资源需要在web.xml中一一列出在<url-pattern>/clear/genurl-pattern>
三、配置成非servlet方式,dubbo的rest接口单独启动一套容器进程,与项目的web容器互不影响,与spring mvc没冲突
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"
xmlns:context=
"http://www.springframework.org/schema/context"
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: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