RELATEED CONSULTING
相关咨询
选择下列产品马上在线沟通
服务时间:8:30-17:00
你可能遇到了下面的问题
关闭右侧工具栏

新闻中心

这里有您想知道的互联网营销解决方案
duboo的使用分析

今天就跟大家聊聊有关duboo的使用分析,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。

五通桥网站制作公司哪家好,找创新互联公司!从网页设计、网站建设、微信开发、APP开发、响应式网站建设等网站项目制作,到程序开发,运营维护。创新互联公司成立与2013年到现在10年的时间,我们拥有了丰富的建站经验和运维经验,来保证我们的工作的顺利进行。专注于网站建设就选创新互联公司

一、背景

随着互联网的发展,网站应用的规模不断扩大,常规的垂直应用架构已无法应对,分布式服务架构以及流动计算架构势在必行。

当越来越的的接口与实现类的增加后,duboo的xml配置会越来越多,为了防止几百几千行的代码,减少开发人员配置xml的工作量,使用duboo的注解模式,减少配置多出问题多的可能性!

二、Dubbo使用案例

Duboo注解

接口类项目:DubboServiceInterface

duboo的使用分析

仅仅是一个接口类项目!接口是普通接口!

duboo的使用分析

注意:将接口类项目打包成jar分别放入服务端项目跟客户端项目!

服务端项目:DubboServiceProvider

duboo的使用分析

实现类fooserviceImpl.java

duboo的使用分析

package com.alibaba.dubbo.demo.imp;

import com.alibaba.dubbo.config.annotation.Service;

import com.alibaba.dubbo.demo.DemoService;

@Service(version="1.0")

public class FooServiceImpl implements DemoService {

@Override

public String sayHello(String name) {

        return "Hello " + name;

    }

}

web.xml 配置扫描内容

duboo的使用分析

  DubboServiceProvider

spring org.springframework.web.servlet.DispatcherServlet

1

spring

*

 

    org.springframework.web.context.ContextLoaderListener

   

contextConfigLocation classpath*:applicationContext.xml

applicationContext.xml 配置

duboo的使用分析

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

   

   

   

   

   

 

   

测试类Provider

 duboo的使用分析

package com.alibaba.dubbo.test;

import java.io.IOException;

import org.junit.Before;

import org.junit.Test;

import org.springframework.context.support.ClassPathXmlApplicationContext;

public class Provider {

@Before

public void setUp() throws Exception {

}

@Test

public void testMain() throws IOException {

ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(

new String[] { "applicationContext.xml" });

context.start();

System.in.read();// 按任意键退出 

}

}

lib下的jar包

duboo的使用分析

客户端项目:DubboServiceConsumer

duboo的使用分析

web.xml 配置扫描内容

duboo的使用分析

applicationContext.xml文件

duboo的使用分析

xmlns:context="http://www.springframework.org/schema/context"

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

   

   

   

   

 

   

测试类:Consumer

duboo的使用分析

package com.unj.dubbotest.action;

import java.io.IOException;

import org.junit.Test;

import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.alibaba.dubbo.config.annotation.Reference;

import com.alibaba.dubbo.demo.DemoService;

public class Consumer{

@Reference(version = "1.0")

private DemoService demoService;

@Test

public  void mainTest() throws IOException {

ClassPathXmlApplicationContext context =new ClassPathXmlApplicationContext(

new String[] {"applicationContext.xml"}); 

       context.start(); 

        demoService = (DemoService)context.getBean("demoService"); // 获取远程服务代理 

       String hello = demoService.sayHello("world"); // 执行远程方法 

       System.out.println( hello ); // 显示调用结果 

   }

}

lib下的jar包

duboo的使用分析

看完上述内容,你们对duboo的使用分析有进一步的了解吗?如果还想了解更多知识或者相关内容,请关注创新互联行业资讯频道,感谢大家的支持。


当前文章:duboo的使用分析
网站网址:http://scyingshan.cn/article/ghcisd.html