大家dubbo服务项目
1. 第一步:web.xm 配置dubbo监听器
<?xml version="1.0"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:spring/service-root.xml</param-value>
</context-param>
<!--this listener must be defined before the spring listener-->
<listener>
<listener-class>com.alibaba.dubbo.remoting.http.servlet.BootstrapListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>dispatcher</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>dispatcher</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
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:dubbo="http://code.alibabatech.com/schema/dubbo"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.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.xsd">
<!--声明dubbo服务基本信息-->
<dubbo:application name="dobboProjectName" owner="zhengyong" organization="dubbox"/>
<dubbo:registry protocol="zookeeper" group="${zookeeper.root}" address="${zookeeper.address}" timeout="50000" />
<dubbo:protocol name="dubbo" port="${dubbo.service.port}" accesslog="true"/>
<bean id="mobileService" class="cn.zhengyong.service.impl.MobileService"/>
<bean id="mobileRestfulService" class="cn.zhengyong.service.restful.impl.MobileHttpService"/>
<!--发布dubbo服务-->
<dubbo:service interface="cn.zhengyong.api.service.intf.IMobileService" ref="mobileService" protocol="dubbo" version="${dubbo.service.mobile.version}" />
<!--发布restful服务-->
<dubbo:service interface="cn.zhengyong.api.service.intf.IMobileService" ref="mobileRestfulService" registry="N/A" protocol="rest" version="${dubbo.service.mobile.version}" />
</beans>
restful 配置
<?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.xsd http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
<dubbo:protocol name="rest" server="servlet" port="${app.port}"/>
</beans>