淘淘商城系列——訂單系統服務端和客戶端工程搭建

李阿昀發表於2017-06-17

首先我們還是先看一眼淘淘商城的系統架構,如下圖所示,可以看到訂單模組是單獨的模組,有服務端還有客戶端,服務端負責儲存訂單,客戶端負責展示訂單。
這裡寫圖片描述
下面我們便開始搭建工程,首先來搭建訂單服務工程——taotao-order。

搭建taotao-order工程

我們可參考taotao-sso工程的建立來搭建訂單服務工程,它是後臺的服務層工程。這個工程是個pom(聚合)工程,包含兩個子模組——taotao-order-interface和taotao-order-service。
首先點選【File】選單選項,並在下拉框中選中【New】,接著點選【Other】,如下:
這裡寫圖片描述
在輸入框中輸入maven,並選擇Maven Project,如下:
這裡寫圖片描述
點選【Next】,勾選Create a simple project核取方塊,如果你不打上這個勾,它會讓你選擇一個骨架,但骨架裡面是沒有pom這個模板的。
這裡寫圖片描述
點選【Next】,出現如下對話方塊,在該對話方塊中定義maven工程的座標,如下:
這裡寫圖片描述
最後點選【Finish】,taotao-order工程即可建立完畢。

搭建taotao-order-interface模組

現在我們來搭建taotao-order-interface模組,方法是在taotao-order工程上右鍵→Maven→New Maven Module Project,如下圖所示。
這裡寫圖片描述
彈出如下對話方塊,勾選”Create a simple project”,在Module Name中輸入taotao-order-interface,然後點選”Next”。
這裡寫圖片描述
選擇該模組的打包方式,我們使用預設的jar,直接點選”Finish”。
這裡寫圖片描述

搭建taotao-order-service模組

搭建taotao-order-service模組,步驟基本上同上,只是打包方式換成war即可,如下圖所示。
這裡寫圖片描述
至於dao和pojo這兩個模組我們不用在taotao-order工程再新建一遍了,因為我們在taotao-manager工程當中便建立好了,我們只需要引用這兩個模組就可以了。

配置taotao-order工程的pom.xml檔案

參考taotao-content聚合工程,把它的pom.xml檔案中的依賴拷過來,只是需要修改下tomcat外掛的埠號,修改為8090(前面已經用到8089了)。
這裡寫圖片描述
為方便大家複製,現把taotao-order工程的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-parent</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>
    <groupId>com.taotao</groupId>
    <artifactId>taotao-order</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>pom</packaging>
    <modules>
        <module>taotao-order-interface</module>
        <module>taotao-order-service</module>
    </modules>
    <dependencies>
        <dependency>
            <groupId>com.taotao</groupId>
            <artifactId>taotao-common</artifactId>
            <version>0.0.1-SNAPSHOT</version>
        </dependency>
    </dependencies>
    <!-- 配置tomcat外掛 -->
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.tomcat.maven</groupId>
                <artifactId>tomcat7-maven-plugin</artifactId>
                <configuration>
                    <port>8090</port>
                    <path>/</path>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

配置taotao-order-interface模組的pom.xml檔案

我們可參考taotao-content-interface工程的pom.xml檔案,由於我們的訂單服務也可能用到pojo,主要新增對taotao-manager-pojo的依賴,如下圖所示。
這裡寫圖片描述

配置taotao-order-service模組的pom.xml檔案

我們可以參考taotao-content-service工程的依賴。由於訂單服務要用到資料庫,因此需要有taotao-manager-dao,把依賴的interface改為我們的taotao-order-interface,taotao-order-service所需要依賴的內容如下所示。

<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-order</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>
    <artifactId>taotao-order-service</artifactId>
    <packaging>war</packaging>
    <dependencies>
        <dependency>
            <groupId>com.taotao</groupId>
            <artifactId>taotao-manager-dao</artifactId>
            <version>0.0.1-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>com.taotao</groupId>
            <artifactId>taotao-order-interface</artifactId>
            <version>0.0.1-SNAPSHOT</version>
        </dependency>
        <!-- Spring -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-beans</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-jdbc</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-aspects</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-jms</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context-support</artifactId>
        </dependency>

        <!-- dubbo相關 -->
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>dubbo</artifactId>
            <!-- 排除依賴 -->
            <exclusions>
                <exclusion>
                    <groupId>org.springframework</groupId>
                    <artifactId>spring</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.jboss.netty</groupId>
                    <artifactId>netty</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <!-- zookeeper的客戶端,你要連線zookeeper,需要把以下兩個jar包加進來 -->
        <dependency>
            <groupId>org.apache.zookeeper</groupId>
            <artifactId>zookeeper</artifactId>
        </dependency>
        <dependency>
            <groupId>com.github.sgroschupf</groupId>
            <artifactId>zkclient</artifactId>
        </dependency>

        <!-- Redis客戶端 -->
        <dependency>
            <groupId>redis.clients</groupId>
            <artifactId>jedis</artifactId>
        </dependency>
    </dependencies>
</project>

框架整合

我們把taotao-content-service的src/main/resources目錄下的mybatis、properties、spring三個目錄貼上到taotao-order-service的src/main/resources目錄中。SqlMapConfig.xml檔案不用動,如下圖所示。
這裡寫圖片描述
properties目錄下的db.properties配置檔案也不用修改,如下圖所示。
這裡寫圖片描述
properties目錄下的resource.properties檔案內容我們清空就可以了,如下圖所示。
這裡寫圖片描述
下面我們再看一下spring目錄下的檔案,applicationContext-dao.xml這個配置檔案是用來運算元據庫的,該檔案的內容不用動。
這裡寫圖片描述
為了大家方便複製,現把該檔案的內容黏貼出來。

<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: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://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.2.xsd">

    <!-- 資料庫連線池 -->
    <!-- 載入配置檔案 -->
    <context:property-placeholder location="classpath:properties/*.properties" />
    <!-- 資料庫連線池 -->
    <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource"
        destroy-method="close">
        <property name="url" value="${jdbc.url}" />
        <property name="username" value="${jdbc.username}" />
        <property name="password" value="${jdbc.password}" />
        <property name="driverClassName" value="${jdbc.driver}" />
        <property name="maxActive" value="10" />
        <property name="minIdle" value="5" />
    </bean>
    <!-- 讓spring管理sqlsessionfactory 使用mybatis和spring整合包中的 -->
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <!-- 資料庫連線池 -->
        <property name="dataSource" ref="dataSource" />
        <!-- 載入mybatis的全域性配置檔案 -->
        <property name="configLocation" value="classpath:mybatis/SqlMapConfig.xml" />
    </bean>
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="basePackage" value="com.taotao.mapper" />
    </bean>
</beans>

spring目錄下的applicationContext-redis.xml檔案我們也原封不動的留著,如下圖所示。
這裡寫圖片描述
為了大家方便複製,現把該檔案的內容黏貼出來。

<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: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://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.2.xsd">

    <!-- 開啟註解 -->
    <!-- <context:annotation-config /> -->

    <!-- redis單機版 -->
    <bean id="jedisPool" class="redis.clients.jedis.JedisPool">
        <constructor-arg name="host" value="192.168.25.128" />
        <constructor-arg name="port" value="6379" />
    </bean>
    <bean id="jedisClientPool" class="com.taotao.content.jedis.JedisClientPool"></bean>
    <!-- 叢集版,注意:單機版和叢集版不能共存!!! -->
    <!-- <bean id="jedisCluster" class="redis.clients.jedis.JedisCluster">
        <constructor-arg name="nodes">
            <set>
                <bean class="redis.clients.jedis.HostAndPort">
                    <constructor-arg name="host" value="192.168.25.128" />
                    <constructor-arg name="port" value="7001" />
                </bean>
                <bean class="redis.clients.jedis.HostAndPort">
                    <constructor-arg name="host" value="192.168.25.128" />
                    <constructor-arg name="port" value="7002" />
                </bean>
                <bean class="redis.clients.jedis.HostAndPort">
                    <constructor-arg name="host" value="192.168.25.128" />
                    <constructor-arg name="port" value="7003" />
                </bean>
                <bean class="redis.clients.jedis.HostAndPort">
                    <constructor-arg name="host" value="192.168.25.128" />
                    <constructor-arg name="port" value="7004" />
                </bean>
                <bean class="redis.clients.jedis.HostAndPort">
                    <constructor-arg name="host" value="192.168.25.128" />
                    <constructor-arg name="port" value="7005" />
                </bean>
                <bean class="redis.clients.jedis.HostAndPort">
                    <constructor-arg name="host" value="192.168.25.128" />
                    <constructor-arg name="port" value="7006" />
                </bean>
            </set>
        </constructor-arg>
    </bean>
    <bean id="jedisClientCluster" class="com.taotao.content.jedis.JedisClientCluster"></bean> -->
</beans>

既然要保留applicationContext-redis.xml配置檔案,那麼就需要把相關包和類拷貝過來,我們參考taotao-content-service工程,將taotao-content-service工程下的com.taotao.content.jedis包整個拷貝到taotao-order-service工程的src/main/java目錄下,如下圖所示。
這裡寫圖片描述
接下來我們修改一下spring目錄下的applicationContext-service.xml檔案,如下圖所示,在taotao-order-interface工程下新建掃描包”com.taotao.order.service”,在taotao-order-service工程下新建”com.taotao.order.service.impl”包,釋出的dubbo服務名稱修改為”taotao-order”,dubbo服務的埠修改為”20884”。
這裡寫圖片描述
為了大家方便複製,現把該檔案的內容黏貼出來。

<?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">

    <context:component-scan base-package="com.taotao.order.service"></context:component-scan>

    <!-- 使用dubbo釋出服務 -->
    <!-- 提供方應用資訊,用於計算依賴關係 -->
    <dubbo:application name="taotao-order" />
    <dubbo:registry protocol="zookeeper" address="192.168.25.128:2181" />
    <!-- 用dubbo協議在20881埠暴露服務 -->
    <dubbo:protocol name="dubbo" port="20884" />
    <!-- 宣告需要暴露的服務介面 -->
    <!-- <dubbo:service interface="com.taotao.content.service.ContentCategoryService" ref="contentCategoryServiceImpl" timeout="300000" /> -->

</beans>

最後來看一下spring目錄下的applicationContext-trans.xml檔案,我們只需要修改一下切面即可,如下圖所示。
這裡寫圖片描述
為了大家方便複製,現把該檔案的內容黏貼出來。

<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: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://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.2.xsd">
    <!-- 事務管理器 -->
    <bean id="transactionManager"
        class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <!-- 資料來源 -->
        <property name="dataSource" ref="dataSource" />
    </bean>
    <!-- 通知 -->
    <tx:advice id="txAdvice" transaction-manager="transactionManager">
        <tx:attributes>
            <!-- 傳播行為 -->
            <tx:method name="save*" propagation="REQUIRED" />
            <tx:method name="insert*" propagation="REQUIRED" />
            <tx:method name="add*" propagation="REQUIRED" />
            <tx:method name="create*" propagation="REQUIRED" />
            <tx:method name="delete*" propagation="REQUIRED" />
            <tx:method name="update*" propagation="REQUIRED" />
            <tx:method name="find*" propagation="SUPPORTS" read-only="true" />
            <tx:method name="select*" propagation="SUPPORTS" read-only="true" />
            <tx:method name="get*" propagation="SUPPORTS" read-only="true" />
        </tx:attributes>
    </tx:advice>
    <!-- 切面 -->
    <aop:config>
        <aop:advisor advice-ref="txAdvice"
            pointcut="execution(* com.taotao.order.service.*.*(..))" />
    </aop:config>
</beans>

下面我們把taotao-content-service工程下的WEB-INF及web.xml,貼上到taotao-order-service的webapp目錄下,修改web.xml檔案中的<display-name>為”taotao-order”。
這裡寫圖片描述
至此,我們的框架就整合好了!

搭建taotao-order-web表現層工程

現在我們就來新建一個taotao-order-web工程,該工程可參考taotao-sso-web工程來搭建喲!
首先點選【File】選單選項,並在下拉框中選中【New】,接著點選【Other】,如下:
這裡寫圖片描述
在輸入框中輸入maven,並選擇Maven Project,如下:
這裡寫圖片描述
點選【Next】,勾選Create a simple project核取方塊,如果你不打上這個勾,它會讓你選擇一個骨架,但骨架裡面是沒有pom這個模板的。
這裡寫圖片描述
點選【Next】,出現如下對話方塊,在該對話方塊中定義maven工程的座標,如下:
這裡寫圖片描述
注意:taotao-order-web工程的打包方式是war,且須依賴父工程。
最後點選【Finish】,taotao-order-web工程就建立好了,但是新建的web工程由於缺少web.xml檔案而報錯,解決方法是在webapp目錄下新建一個WEB-INF目錄,並在該目錄下新建web.xml檔案,至於該檔案的內容具體是什麼,後面會具體給出,這裡我們並不著急。
接著配置taotao-order-web工程的pom.xml檔案,我們可參考taotao-cart-web工程的pom.xml檔案來配置,只需稍作修改,將依賴的interface修改為taotao-order-interface(第二個<dependency>),最下面的tomcat外掛埠號配置為8091,修改好的依賴如下:

<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-parent</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>
    <groupId>com.taotao</groupId>
    <artifactId>taotao-order-web</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>
    <dependencies>
        <!-- 依賴taotao-common -->
        <dependency>  
            <groupId>com.taotao</groupId>  
            <artifactId>taotao-common</artifactId>  
            <version>0.0.1-SNAPSHOT</version>  
        </dependency>
        <!-- 依賴taotao-order-interface -->
        <dependency>  
            <groupId>com.taotao</groupId>  
            <artifactId>taotao-order-interface</artifactId>  
            <version>0.0.1-SNAPSHOT</version>  
        </dependency>
        <!-- Spring -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-beans</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-jdbc</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-aspects</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-jms</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context-support</artifactId>
        </dependency>
        <!-- JSP相關 -->
        <dependency>
            <groupId>jstl</groupId>
            <artifactId>jstl</artifactId>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jsp-api</artifactId>
            <scope>provided</scope>
        </dependency>

        <!-- dubbo相關 -->
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>dubbo</artifactId>
            <!-- 排除依賴 -->
            <exclusions>
                <exclusion>
                    <groupId>org.springframework</groupId>
                    <artifactId>spring</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.jboss.netty</groupId>
                    <artifactId>netty</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <!-- zookeeper的客戶端,你要連線zookeeper,需要把以下兩個jar包加進來 -->
        <dependency>
            <groupId>org.apache.zookeeper</groupId>
            <artifactId>zookeeper</artifactId>
        </dependency>
        <dependency>
            <groupId>com.github.sgroschupf</groupId>
            <artifactId>zkclient</artifactId>
        </dependency>

        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
        </dependency>
    </dependencies>
    <!-- 配置tomcat外掛 -->
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.tomcat.maven</groupId>
                <artifactId>tomcat7-maven-plugin</artifactId>
                <configuration>
                    <port>8091</port>
                    <path>/</path>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

緊接著來配置資原始檔,我們亦可參考taotao-cart-web工程,將src/main/resources目錄下的兩個資料夾拷貝過來。先看resource目錄下的resource.properties檔案,該檔案是用來配置常量的,目前我們還沒有寫業務程式碼,該檔案暫時保持為空。
這裡寫圖片描述
下面再看下spring目錄下的springmvc.xml,修改要掃描的包和引用dubbo服務兩項配置,要掃描的包”com.taotao.order.controller”我們是需要新建的,如下圖所示。
這裡寫圖片描述
為了大家方便複製,現把該檔案的內容貼出。

<?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">

    <!-- 載入屬性檔案 -->
    <context:property-placeholder location="classpath:resource/resource.properties" />

    <context:component-scan base-package="com.taotao.order.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="taotao-order-web"/>
    <dubbo:registry protocol="zookeeper" address="192.168.25.128:2181"/>    
    <!-- <dubbo:reference interface="com.taotao.service.ItemService" id="itemService" /> -->

</beans>

最後來配置web.xml,我們依然可參考taotao-cart-web工程的web.xml,首先需要在webapp目錄下新建一個WEB-INF目錄,並拷貝taotao-cart-web工程的web.xml檔案到WEB-INF目錄下,我們需要修改的地方是名字,把原來所有的”taotao-cart-web”都更改為”taotao-order-web”(可以使用全文替換),如下圖所示。
這裡寫圖片描述
這樣,我們的服務端和客戶端工程便都搭建好了。

相關文章