B2B2C-1 dubbox-4-查询品牌后台实现

三个模块:

manager(对应manager-web)运营商管理模块

sellergoods(对应sellergoods-api和sellergoods-service)商品模块

shop(对应shop-web)商家模块

利用dubbo服务实现功能调用

sellergoods-api:服务提供者api

sellergoods-service:真正的服务提供者

shop-web:服务消费者

--------------------------------------------------------------------------------具体实现--------------------------------------------------------------------------------------------------------

利用dubbo的注解方式实现

sellergoods-service中的spring配置文件内容:

<?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.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.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:protocol name="dubbo" port="20881"></dubbo:protocol>

<dubbo:application name="pyg-sellergoods-service"/>
<dubbo:registry address="zookeeper://localhost:2181"/>
<dubbo:annotation package="com.pyg.sellergoods.service.impl" />

<!-- 声明需要暴露的服务 -->
<!--<dubbo:service interface="com.pyg.brand.service.BrandService" ref="brandService" />
&lt;!&ndash; 服务实现 &ndash;&gt;
<bean id="brandService" class="com.pyg.sellergoods.service.impl.BrandServiceImpl" />-->

</beans>

调用者的spring配置文件内容:

<?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.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.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">
<context:property-placeholder location="classpath:config/application.properties" />
<context:component-scan base-package="com.pyg.manager.controller" />
<mvc:annotation-driven>
<mvc:message-converters register-defaults="true">
<bean class="com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter">
<property name="supportedMediaTypes" value="application/json"/>
<property name="features">
<array>
<value>WriteMapNullValue</value>
<value>WriteDateUseDateFormat</value>
</array>
</property>
</bean>
</mvc:message-converters>
</mvc:annotation-driven>

<!-- 引用dubbo 服务 -->
<dubbo:application name="pyg-manager-web" />
<dubbo:registry address="zookeeper://localhost:2181"/>
<dubbo:annotation package="com.pyg.manager.controller" />
<!--<dubbo:reference id="brandService" interface="com.pyg.brand.service.BrandService"/>-->

</beans>
注意因为web.xml文件中配置的路径是<servlet-mapping>中的<url-pattern>*.do<....>
所以@RequestMapping("/getAllBrand.do") 访问路径必须是.do的形式

posted on 2018-09-26 15:55  companion  阅读(222)  评论(0编辑  收藏  举报