学习笔记文档:https://pan.baidu.com/s/1bujZygn3FgYbiDeVJgB-5g 密码:zap1
soa架构(面向服务):
dubbo的架构:
applicationContext.xml(服务提供者的Spring配置文件,配置dubbo,发布服务到注册中心):
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:dubbo="http://code.alibabatech.com/schema/dubbo" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.2.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.2.xsd
http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.2.xsd">
<!-- 加入dubbo的标签头,和约束。 -->
<context:component-scan base-package="cn.e3mall.service"></context:component-scan>
<!-- 使用dubbo发布服务 -->
<!-- 服务提供方应用信息(项目工程名),用于计算依赖关系 -->
<dubbo:application name="e3-manager" />
<!-- zookeeper注册中心(zookeeper可以是集群 多个IP) -->
<dubbo:registry protocol="zookeeper"
address="192.168.25.154:2181,192.168.25.154:2182,192.168.25.154:2183" />
<!-- 用dubbo协议在20880端口暴露服务 -->
<dubbo:protocol name="dubbo" port="20880" />
<!-- 声明需要暴露的服务接口。可以通过timeout属性配置超时时间(单位毫秒) -->
<dubbo:service interface="cn.e3mall.service.ItemService" ref="itemServiceImpl" />
</beans>
pom.xml(服务提供方,maven项目的配置文件,添加dubbo的jar包依赖):
<!-- dubbo相关的Jar包依赖 -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>dubbo</artifactId>
<exclusions>
<exclusion> <!— 如果Spring Jar包冲突。排除低版本的Spring的jar包。 -->
<groupId>org.springframework</groupId>
<artifactId>spring</artifactId>
</exclusion>
<exclusion>
<groupId>org.jboss.netty</groupId>
<artifactId>netty</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.zookeeper</groupId>
<artifactId>zookeeper</artifactId>
</dependency>
<dependency>
<groupId>com.github.sgroschupf</groupId>
<artifactId>zkclient</artifactId>
</dependency>
springmvc.xml(服务调用者的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-4.2.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.2.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-4.2.xsd">
<!-- 添加dubbo的标签头,和约束 -->
<context:component-scan base-package="cn.e3mall.controller" />
<mvc:annotation-driven />
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" />
</bean>
<!-- 引用dubbo服务。(服务调用者) -->
<dubbo:application name="e3-manager-web"/> <!--项目工程名称 -->
<dubbo:registry protocol="zookeeper" address="192.168.25.154:2181,192.168.25.154:2182,192.168.25.154:2183"/>
<!-- interface要和服务提供者注册的interface保持一致。 -->
<dubbo:reference interface="cn.e3mall.service.ItemService" id="itemService" />
</beans>
pom.xml(服务调用者,maven项目的配置文件,添加dubbo的jar包依赖):
<!-- dubbo相关的Jar包依赖 -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>dubbo</artifactId>
<exclusions>
<exclusion> <!— 如果Spring Jar包冲突。排除低版本的Spring的jar包。 -->
<groupId>org.springframework</groupId>
<artifactId>spring</artifactId>
</exclusion>
<exclusion>
<groupId>org.jboss.netty</groupId>
<artifactId>netty</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.zookeeper</groupId>
<artifactId>zookeeper</artifactId>
</dependency>
<dependency>
<groupId>com.github.sgroschupf</groupId>
<artifactId>zkclient</artifactId>
</dependency>