• (转)淘淘商城系列——服务调用测试


    http://blog.csdn.net/yerenyuan_pku/article/details/72761467

    我们已经发布dubbo服务,现在本文来测试一下引用dubbo服务是否好使。在启动taotao-manager工程之前,我们先检查我们的zookeeper当前是否处于开启状态,使用cd /usr/local/zookeeper/zookeeper-3.4.6/bin命令切换到bin目录下,然后使用./zkServer.sh status来查看其启动状态,如果zookeeper没启动,就使用./zkServer.sh start命令来启动它。如果看到以下所示结果,说明其是启动状态。 

    我们还需要做件事情,就是配置防火墙,因为防火墙不让我们访问8080和8081端口,为了方便,我们直接关闭防火墙并且设置开机也不启动,大家可按如下步骤进行,我截图如下: 

    • service iptables stop:关闭防火墙。
    • hkconfig iptables off:禁止防火墙开机自启动。
    • chkconfig iptables --list:查看七种情况还没有开机自启的情况,如果都是”关闭”状态,说明已经都禁止开机自启动了。

    下面我们启动taotao-manager工程(taotao-manager-service包含在taotao-manager工程下,因此启动taotao-mananger也相当于启动了taotao-mananger-service),关于如何启动聚合工程大家可以参考淘淘商城系列——使用maven tomcat插件启动聚合工程这篇博客进行学习。如果我们看到下图时,则说明我们的taotao-manager工程正常启动了。 

    如果长时间未看到上图所示信息,很有可能是我们的zookeeper未启动,我们需要打开虚拟机并启动zookeeper。 
    启动完taotao-manager工程之后,我们来启动taotao-manager-web工程,由于该工程依赖聚合工程taotao-manager下的taotao-manager-interface和taotao-manager-pojo,为了一次性解决问题,我们直接安装taotao-manager工程即可,按如下图所示操作。 

    安装完之后,我们到本地maven仓库位置查看下是否生成了我们想要的包。可以看到都正常生成了。 

    下面我们便来启动taotao-manager-web工程,看到如下图所示信息说明taotao-manager-web工程正常启动了。

    下面我们便来试着访问一下dubbo服务,我们从数据库tb_item数据库表中随便找一个商品id,比如:605616,如下图所示。 

    我们在地址栏中输入:http://localhost:8080/item/605616来访问服务端,我们会看到如下图所示的错误。 

    出现上图错误的原因是我们在本地没有把taotao-manager-dao工程下的mapper相关的.xml文件编译进来,如下图所示,发现只有class文件,没有.xml文件。 

    要解决这个问题我们需要把.xml文件也加载进来,方法是在taotao-manager-dao工程的pom.xml文件中添加如下一段配置。

    <!-- 如果不添加此节点mybatis的mapper.xml文件都会被漏掉。 -->
    <build>
        <resources>
               <resource>
                   <directory>src/main/java</directory>
                   <includes>
                       <include>**/*.properties</include>
                       <include>**/*.xml</include>
                   </includes>
                   <filtering>false</filtering>
               </resource>
           </resources>
    </build>
    • 1

    添加完配置之后taotao-manager-dao工程的pom.xml文件的完整内容如下:

    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
        <parent>
            <groupId>com.taotao</groupId>
            <artifactId>taotao-manager</artifactId>
            <version>0.0.1-SNAPSHOT</version>
        </parent>
        <artifactId>taotao-manager-dao</artifactId>
    
        <dependencies>
            <dependency>
                <groupId>com.taotao</groupId>
                <artifactId>taotao-manager-pojo</artifactId>
                <version>0.0.1-SNAPSHOT</version>
            </dependency>
            <!-- Mybatis -->
            <dependency>
                <groupId>org.mybatis</groupId>
                <artifactId>mybatis</artifactId>
            </dependency>
            <dependency>
                <groupId>org.mybatis</groupId>
                <artifactId>mybatis-spring</artifactId>
            </dependency>
            <dependency>
                <groupId>com.github.miemiedev</groupId>
                <artifactId>mybatis-paginator</artifactId>
            </dependency>
            <dependency>
                <groupId>com.github.pagehelper</groupId>
                <artifactId>pagehelper</artifactId>
            </dependency>
            <!-- MySql -->
            <dependency>
                <groupId>mysql</groupId>
                <artifactId>mysql-connector-java</artifactId>
            </dependency>
            <!-- 连接池 -->
            <dependency>
                <groupId>com.alibaba</groupId>
                <artifactId>druid</artifactId>
            </dependency>
        </dependencies>
    
        <!-- 如果不添加此节点mybatis的mapper.xml文件都会被漏掉。 -->
        <build>
            <resources>
                <resource>
                    <directory>src/main/java</directory>
                    <includes>
                        <include>**/*.properties</include>
                        <include>**/*.xml</include>
                    </includes>
                    <filtering>false</filtering>
                </resource>
            </resources>
        </build>
    </project>
    • 1

    下面我们再重启taotao-manager工程,启动完之后,我们再看下是否已经生成了.xml文件,发现已经成功生成了。 

    这时,我们再访问http://localhost:8080/item/605616,这时我们又会看到如下图所示错误。 

    这个错误是因为我们的pojo类没有实现序列化接口,我们把所有不是以Example结尾的pojo实现序列化,如下图所示。 

    由于我们改动了taotao-manager-dao和taotao-manager-pojo,因此我们最好再重新打下包,就是把taotao-manager工程maven install一下。重新打包后,我们重启taotao-manager工程。然后再访问http://localhost:8080/item/605616,发现可以正常访问到数据了!! 

  • 相关阅读:
    swift运算符使用_02_swift基本数据类型
    OSChina-01Swift终端命令行
    开源框架汇总-01-第三方
    修改App名称-01-修改项目中APP名
    NSAttributedString.h 中文本属性key的说明-06
    SQLite总结-05
    Linux系统判断gcc是否安装
    翻译文件结构规范
    并行SVN版本控制
    页面设计规范
  • 原文地址:https://www.cnblogs.com/telwanggs/p/6934263.html
Copyright © 2020-2023  润新知