临时->☆雪无痕☆ Dubbo与Zookeeper、SpringMVC整合和使用

作为dubbo框架初学者,能让框架跑起来非常不容易,非常感谢网上诸多大神提供的文章,本人参考文章地址是:https://my.oschina.net/xshuai/blog/891281

不过别人的记录终究不适合自己,所以还是按照自己的风格简单记录下学习dubbo整合的步骤。

windows环境介绍:

  myeclipse 10

  jdk1.6

  tomcat 6.0.35  

一、安装Zookeeper

  1.通过链接下载对应的包 http://www.apache.org/dist/zookeeper/

  2.Zookeeper下载后解压即可,见下图

  

  3.进入到conf里面,会看到zoo_sample.cfg文件。将zoo_sample.cfg改成bak文件,并复制一个修改为zoo.cfg,修改相关配置内容,注意修改的日志文件夹需要自己手动创建

   

  4.进入D:\zookeeper-3.4.6\bin,双击zkServer.cmd,见到如下界面,就表示zookeeper已启动成功

  

二、安装dubbo

  1.本人使用的是dubbo-admin-2.5.3.war,下载地址:http://pan.baidu.com/s/1eSnuqEQ

  2.拷贝一个新的tomcat,并将tomcat/webapps里面的ROOT文件夹删掉

  3.将dubbo-admin-2.5.3.war重命名为ROOT.war,并拷贝到tomcat/webapps目录下

  4.启动tomcat

   

    出现上述问题表示你没有启动zookeeper

   5.dubbo发布成功后,输入http://localhost:8889/dubbo-admin-2.5.3/,此时出现登录页面,输入root/root进行登录,登录成功后如图

    

三、创建服务提供服务(provider)

  项目结构如下图

  

  相应的类中的代码如下:

  web.xml

复制代码

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" 
    xmlns="http://java.sun.com/xml/ns/javaee" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
    http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
  <display-name></display-name>    
  
  <listener-class>
        org.springframework.web.context.ContextLoaderListener
    </listener-class>

    <servlet>
        <servlet-name>provider</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>
                classpath:applicationContext.xml,classpath:applicationContext-servlet.xml
            </param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>provider</servlet-name>
        <url-pattern>*.do</url-pattern>
    </servlet-mapping>
    
    <!-- 字符过滤器 -->
    <filter>
        <filter-name>Set Character Encoding</filter-name>
        <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
        <init-param>
            <param-name>encoding</param-name>
            <param-value>UTF-8</param-value>
        </init-param>
    </filter>
    <filter-mapping>
        <filter-name>Set Character Encoding</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
  
  
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
</web-app>

复制代码

  DemoService.java  

package com.provider;

public interface DemoService {
    
    String sayHello(String name);
}

  DemoServiceImpl.java  

复制代码

package com.provider;

import org.springframework.stereotype.Service;

@Service(value="demoService")
public class DemoServiceImpl implements DemoService{

    public String sayHello(String name) {
        return "Hello Dubbo,Hello " + name;
    }

}

复制代码

  applicationContext.xml

  

复制代码

<?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:aop="http://www.springframework.org/schema/aop"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:jdbc="http://www.springframework.org/schema/jdbc"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="          
      http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd          
      http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd  
      http://www.springframework.org/schema/tx 
      http://www.springframework.org/schema/tx/spring-tx-3.1.xsd          
      http://www.springframework.org/schema/aop 
      http://www.springframework.org/schema/aop/spring-aop-3.1.xsd"
    >

    <context:component-scan base-package="com.**"></context:component-scan>

    <!-- 引入服务提供者配置文件 -->
    <import resource="dubbo-provider.xml" /> 
</beans>

复制代码

  dubbo-provider.xml  

复制代码

<?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:application name="hello-world-provider"  />
 
    <!-- 使用multicast广播注册中心暴露服务地址 -->
   <!--  <dubbo:registry address="multicast://224.5.6.7:1234" /> -->
 
     <!-- 使用zookeeper注册中心暴露服务地址 -->
    <dubbo:registry address="zookeeper://127.0.0.1:2181" />
 
    <!-- 用dubbo协议在20880端口暴露服务 -->
    <dubbo:protocol name="dubbo" port="20880" />
 
    <!-- 声明需要暴露的服务接口 -->
    <dubbo:service interface="com.provider.DemoService" ref="demoService" />
 
    <!-- 和本地bean一样实现服务 -->
    <!-- 
    <bean id="demoService" class="com.provider.DemoServiceImpl" />
     -->
</beans>

复制代码

  applicationContext-servlet.xml   

复制代码

<?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:aop="http://www.springframework.org/schema/aop"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:jdbc="http://www.springframework.org/schema/jdbc"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="          
      http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd          
      http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd          
      http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd          
      http://www.springframewor.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
      http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd"
    default-autowire="byName">

    <!-- 默认的注解映射的支持 -->
    <mvc:annotation-driven>
        <mvc:message-converters register-defaults="true">
             <bean class ="org.springframework.http.converter.StringHttpMessageConverter">  
                <property name ="supportedMediaTypes">  
                     <list>  
                         <value>text/plain;charset=UTF-8</value> 
                     </list>  
                </property>  
             </bean>  
        </mvc:message-converters>
    </mvc:annotation-driven>

    <!-- 视图解释类 -->
    <bean id="viewResolver"
        class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/jsp/" />
        <property name="suffix" value=".jsp" />
        <property name="viewClass"
            value="org.springframework.web.servlet.view.JstlView" />
    </bean>

    <!-- 加载静态资源 -->
    <mvc:resources mapping="/css/**" location="/css/" />
    <mvc:resources mapping="/js/**" location="/js/" />
    <mvc:resources mapping="/images/**" location="/images/" />
</beans>

复制代码

四、创建调用服务(customer)

  customer服务架构和provider一致,拷贝一个即可

  相应的代码如下:

  applicationContext.xml

复制代码

<?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:aop="http://www.springframework.org/schema/aop"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:jdbc="http://www.springframework.org/schema/jdbc"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="          
      http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd          
      http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd  
      http://www.springframework.org/schema/tx 
      http://www.springframework.org/schema/tx/spring-tx-3.1.xsd          
      http://www.springframework.org/schema/aop 
      http://www.springframework.org/schema/aop/spring-aop-3.1.xsd"
    >

    <context:component-scan base-package="com.**"></context:component-scan>

    <!-- 引入消费者配置文件 -->
    <import resource="dubbo-consumer.xml" /> 
</beans>

复制代码

  dubbo-consumer.xml

  

复制代码

<?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:application name="hello-world-customer"/>
    <!-- 使用multicast广播注册中心暴露发现服务地址 -->
    <!-- <dubbo:registry address="multicast://224.5.6.7:1234" /> -->  
    <dubbo:registry address="zookeeper://127.0.0.1:2181" check="false"/>
    <!-- 生成远程服务代理,可以和本地bean一样使用demoService -->
    <dubbo:reference id="demoService" interface="com.provider.DemoService" check="false"/>
</beans>

复制代码

  applicationContext-servlet.xml 和provider中的代码一致,就不贴出来了,本项目中其实这个文件可以不用

  CustomerAction.java测试类  

复制代码

package com.customer;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.provider.DemoService;

@Controller
@RequestMapping(value="/customerTest")
public class CustomerAction {
    
    @Resource(name="demoService")
    private DemoService demoService;

    @RequestMapping(value="/test.do")
    public ModelAndView test(HttpServletRequest request,HttpServletResponse response){
        System.out.println("成功");
        String result = demoService.sayHello("world");
        System.out.println(result);
        return null;
    }
    
}

复制代码

 

五、共享服务

  注意:需要将服务提供的接口打成jar包,放入customer中

六、测试

  步骤:1、先启动zookeeper服务

     2、启动dubbo服务

     3、启动provider服务

     4、启动customer服务

  正常会出现如下界面

  

  错误总结:

  若按照上述测试步骤分别在不同的tomcat中启动服务,应该一切正常

  若2、3、4这三步放在同一个tomcat中启动,会出现如下错误。

  

看下关键异常:No provider available for the service

此异常是由于服务没有可以使用的提供者,就是说在zookeeper注册中心(zookeeper-url)中没有可供消费者调用的url,消费者访问提供者就失败了。

具体原因分析:由于dobbo在启动的时候会去检查各服务之间的依赖关系,由于启动的时候消费者没有检查到提供者提供的服务(此时可能提供者还没启动),所以报错

在消费者配置文件中,需要将<dubbo:registry address="zookeeper://127.0.0.1:2181"/>修改为<dubbo:registry address="zookeeper://127.0.0.1:2181" check="false"/>

由于dubbo在注册的时候是默认会检查服务的依赖关系的

 

内容概要:本文档是一份关于交换路由配置的学习笔记,系统地介绍了网络设备的远程管理、交换机路由器的核心配置技术。内容涵盖Telnet、SSH、Console三种远程控制方式的配置方法;详细讲解了VLAN划分原理及Access、Trunk、Hybrid端口的工作机制,以及端口镜像、端口汇聚、端口隔离等交换技术;深入解析了STP、MSTP、RSTP生成树协议的作用配置步骤;在路由部分,涵盖了IP地址配置、DHCP服务部署(接口池全局池)、NAT转换(静态动态)、静态路由、RIPOSPF动态路由协议的配置,并介绍了策略路由ACL访问控制列表的应用;最后简要说明了华为防火墙的安全区域划分基本安全策略配置。; 适合人群:具备一定网络基础知识,从事网络工程、运维或相关技术岗位1-3年的技术人员,以及准备参加HCIA/CCNA等认证考试的学习者。; 使用场景及目标:①掌握企业网络中常见的交换路由配置技能,提升实际操作能力;②理解VLAN、STP、OSPF、NAT、ACL等核心技术原理并能独立完成中小型网络搭建调试;③通过命令示例熟悉华为设备CLI配置逻辑,为项目实施故障排查提供参考。; 阅读建议:此笔记以实用配置为主,建议结合模拟器(如eNSP或Packet Tracer)动手实践每一条命令,对照拓扑理解数据流向,重点关注VLAN间通信、路由选择机制、安全策略控制等关键环节,并注意不同设备型号间的命令差异。
多旋翼无人机组合导航系统-多源信息融合算法(Matlab代码实现)内容概要:本文围绕多旋翼无人机组合导航系统,重点介绍了基于多源信息融合算法的设计实现,利用Matlab进行代码开发。文中采用扩展卡尔曼滤波(EKF)作为核心融合算法,整合GPS、IMU(惯性测量单元)、里程计电子罗盘等多种传感器数据,提升无人机在复杂环境下的定位精度稳定性。特别是在GPS信号弱或丢失的情况下,通过IMU惯导数据辅助导航,实现连续可靠的位姿估计。同时,文档展示了完整的算法流程Matlab仿真实现,涵盖传感器数据预处理、坐标系转换、滤波融合及结果可视化等关键环节,体现了较强的工程实践价值。; 适合人群:具备一定Matlab编程基础信号处理知识,从事无人机导航、智能控制、自动化或相关领域研究的研究生、科研人员及工程技术人员。; 使用场景及目标:①应用于多旋翼无人机的高精度组合导航系统设计;②用于教学科研中理解多传感器融合原理EKF算法实现;③支持复杂环境下无人机自主飞行定位系统的开发优化。; 阅读建议:建议结合Matlab代码理论推导同步学习,重点关注EKF的状态预测更新过程、多传感器数据的时间同步坐标变换处理,并可通过修改噪声参数或引入更多传感器类型进行扩展实验。
源码来自:https://pan.quark.cn/s/28c3abaeb160 在高性能计算(High Performance Computing,简称HPC)范畴内,处理器的性能衡量对于改进系统构建及增强运算效能具有关键价值。 本研究聚焦于一种基于ARM架构的处理器展开性能评估,并就其性能Intel Xeon等主流商业处理器进行对比研究,特别是在浮点运算能力、存储器带宽及延迟等维度。 研究选取了高性能计算中的典型任务,诸如Stencils计算方法等,分析了在ARM处理器上的移植编译过程,并借助特定的执行策略提升运算表现。 此外,文章还探讨了ARM处理器在“绿色计算”范畴的应用前景,以及面向下一代ARM服务器级SoC(System on Chip,简称SoC)的性能未来探索方向。 ARM处理器是一种基于精简指令集计算机(Reduced Instruction Set Computer,简称RISC)架构的微处理器,由英国ARM Holdings公司研发。 ARM处理器在移动设备、嵌入式系统及服务器级计算领域获得广泛应用,其设计优势体现为高能效比、低成本且易于扩展。 当前的ARMv8架构支持64位指令集,在高性能计算领域得到普遍采用。 在性能测试环节,重点考察了处理器的浮点运算能力,因为浮点运算在科学计算、图形渲染数据处理等高性能计算任务中扮演核心角色。 实验数据揭示,ARM处理器在双精度浮点运算方面的性能达到475 GFLOPS,相当于Intel Xeon E5-2680 v3处理器性能的66%。 尽管如此,其内存访问带宽高达105 GB/s,超越Intel Xeon处理器。 这一发现表明,在数据密集型应用场景下,ARM处理器能够展现出主流处理器相匹敌的性能水平。 在实践...
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值