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" />
<!– 服务实现 –>
<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的形式
分类:
项目
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· winform 绘制太阳,地球,月球 运作规律
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理