dubbo配置表现层

表现层工程

改造e3-manager-web工程。

第一步:删除mybatis、和spring的配置文件。只保留springmvc.xml

第二步:修改e3-manager-web的pom文件,

1.修改parent为e3-parent

2.添加spring和springmvc的jar包的依赖

3.删除e3-mangager-service的依赖

4.添加dubbo的依赖

<!-- 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>
        <dependency>
            <groupId>org.apache.zookeeper</groupId>
            <artifactId>zookeeper</artifactId>
        </dependency>
        <dependency>
            <groupId>com.github.sgroschupf</groupId>
            <artifactId>zkclient</artifactId>
        </dependency>

5.e3-mangager-web添加对e3-manager-Interface的依赖。

第三步:修改springmvc.xml,在springmvc的配置文件中添加服务的引用。

<?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:component-scan base-package="cn.e3mall.controller" />
    <!-- springmvc三大件 -->
    <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.2.188:2181"/>    
    <dubbo:reference interface="cn.e3mall.service.ItemService" id="itemService" />
    
</beans>

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

      <!-- 配置连接zookeeper -->

      <dubbo:registry protocol="zookeeper" address="192.168.25.154:2181,192.168.25.154:2182,192.168.25.154:2183"/> 

      <!-- 跟普通bean一样 在controller引用 需加入e3-manager-interface依赖-->

      <dubbo:reference interface="cn.e3mall.service.ItemService" id="itemService" />

     

</beans>

第四步:在e3-manager-web工程中添加tomcat插件配置。

<build>
        <plugins>
            <!-- 配置Tomcat插件 -->
            <plugin>
                <groupId>org.apache.tomcat.maven</groupId>
                <artifactId>tomcat7-maven-plugin</artifactId>
                <configuration>
                    <path>/</path>
                    <port>8081</port>
                </configuration>
            </plugin>
        </plugins>
    </build>

第五步:maven install e3-manager

第六步:测试(要先启动zookeeper 再启动服务者 最后启动消费者 localhost:8081)clean tomcat7:run

第七步:引入log4j.properties

第八步:实体类implements Serializable 输入maven install e3-manager-pojo

第八步:dubbo监控中心

需要安装tomcat,然后部署监控中心即可。

1、部署监控中心:

[root@localhost ~]# cp dubbo-admin-2.5.4.war apache-tomcat-7.0.47/webapps/dubbo-admin.war

2.启动tomcat

3.访问http://192.168.2.188:8080/dubbo-admin/

用户名:root

密码:root

猜你喜欢

转载自blog.csdn.net/etna_hh/article/details/82119463
今日推荐