return “test1Service3_1…” ;

}

}

4.配置 配置文件

provider.xml

xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance” xmlns:p=“http://www.springframework.org/schema/p”

xmlns:dubbo=“http://code.alibabatech.com/schema/dubbo”

xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd

http://code.alibabatech.com/schema/dubbo

http://code.alibabatech.com/schema/dubbo/dubbo.xsd">

5.1 启动spring 容器 ;java代码启动

provder3.java

import org.springframework.context.support.ClassPathXmlApplicationContext;

/**

Created by shirenchuang on 2017/3/16.

*/

public class Provider3 {

public static void main(String[] args) throws Exception {

ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(

new String[] {“provider.xml”});

context.start();

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

}

}

5.2 也可以部署到tomcat 中去;那就要配置一下 web.xml 文件了

例如:看 dubbo-service1_1-project 的配置文件

里面的那些配置文件就不贴出来了 ;下载源代码看就行了 ;

最好可以打包成war 部署到tomcat 中 也是一样的效果

6.步骤5.1 或者5.2 部署成功之后的效果 ,打开dubbo-admin 查看

7. 服务注册成功了 ,那么怎么使用呢?

三 . 如何消费 提供者提供的服务----消费者

============================

刚刚发布了 service3 ,并且保持它一直在启动状态(不要把provder3 停止就行了)

可以在dubbo-admin 看到它是没有消费者的,现在我们在 Controller 层来消费它;

1. Controller 的配置

web.xml

dispatcher

org.springframework.web.servlet.DispatcherServlet

contextConfigLocation

classpath:applicationContext.xml

0

spring-mvc.xml  开启自动扫描

xmlns:context=“http://www.springframework.org/schema/context”

xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance” xmlns:mvc=“http://www.springframework.org/schema/mvc”

xsi:schemaLocation="http://www.springframework.org/schema/beans

http://www.springframework.org/schema/beans/spring-beans.xsd

http://www.springframework.org/schema/context

http://www.springframework.org/schema/context/spring-context-3.0.xsd

http://www.springframework.org/schema/mvc

http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd">

dubbo-config.xml  就是消费者 的配置文件

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

配置 了需要消费的服务  service3 ;然后在Controller 中 就可以自己 通过注解 @Autowired 使用

@Autowired

private Test1Service3 test1Service3;

@RequestMapping(value = “/test3”)

@ResponseBody

public String test3(){

return test1Service3.test1Service3_1();

}

2.1 tomcat启动服务…

请求接口…

启动完了可以看到的是  服务 显示正常 表示 有提供者 又有消费者呢 ;

注意  如果注册中心 没有注册成功的话 启动会报错

2.2 本地 测试调用远程服务

comsumer.xml  消费者配置

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

comsumer2.java

public class Consumer2 {

public static void main(String[] args) throws Exception {

ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[]

{“consumer.xml”});

context.start();

Test1Service3 test1Service3 = (Test1Service3)context.getBean(“test1Service3”); // 获取远程服务代理

String s = test1Service3.test1Service3_1(); // 执行远程方法

System.out.print(“end…”+s);

}

}

String s = test1Service3.test1Service3_1();

打个断点,然后去dubbo-admin 看 可以发现 出现消费者;

放掉断点 ,消费者消失;并且 打印结果:end…test1Service3_1…

===

四. 服务之间相互调用,每个服务既是消费者 又是提供者

============================

1. 整体怎么配置

看服务  service1 ; 既是提供者 ,又是消费者 ;

Test1Service1Impl 文件

package com.dubbo.service1.impl;

import com.dubbo.service1.Test1Service1;

import com.dubbo.service1.Test2Service1;

import com.dubbo.service2.Test1Service2;

import com.dubbo.service3.Test1Service3;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Service;

/**

Created by shirenchuang on 2017/3/16.

*/

@Service

public class Test1Service1Impl implements Test1Service1{

@Autowired

private Test1Service3 test1Service3;

@Autowired

private Test2Service1 test2Service1 ;

public String test1Service1_1() {

String s = test1Service3.test1Service3_1();

return s+“test1Service1_1…”;

}

小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。

深知大多数初中级Java工程师,想要提升技能,往往是自己摸索成长,但自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!

因此收集整理了一份《2024年最新Java开发全套学习资料》送给大家,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。

由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频

如果你觉得这些内容对你有帮助,可以添加下面V无偿领取!(备注Java)

最后

Java架构进阶面试及知识点文档笔记

这份文档共498页,其中包括Java集合,并发编程,JVM,Dubbo,Redis,Spring全家桶,MySQL,Kafka等面试解析及知识点整理

Java分布式高级面试问题解析文档

其中都是包括分布式的面试问题解析,内容有分布式消息队列,Redis缓存,分库分表,微服务架构,分布式高可用,读写分离等等!

互联网Java程序员面试必备问题解析及文档学习笔记

Java架构进阶视频解析合集

.(img-aRsHkyIs-1711390553099)] [外链图片转存中…(img-1M7ntj1A-1711390553099)]

由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频

如果你觉得这些内容对你有帮助,可以添加下面V无偿领取!(备注Java) [外链图片转存中…(img-81intBWM-1711390553100)]

最后

Java架构进阶面试及知识点文档笔记

这份文档共498页,其中包括Java集合,并发编程,JVM,Dubbo,Redis,Spring全家桶,MySQL,Kafka等面试解析及知识点整理

[外链图片转存中…(img-112e6pXX-1711390553100)]

Java分布式高级面试问题解析文档

其中都是包括分布式的面试问题解析,内容有分布式消息队列,Redis缓存,分库分表,微服务架构,分布式高可用,读写分离等等!

[外链图片转存中…(img-0ovyLJmu-1711390553101)]

互联网Java程序员面试必备问题解析及文档学习笔记

[外链图片转存中…(img-Eu0XhMVH-1711390553101)]

Java架构进阶视频解析合集

本文已被CODING开源项目:【一线大厂Java面试题解析+核心总结学习笔记+最新讲解视频+实战项目源码】收录

推荐链接

评论可见,请评论后查看内容,谢谢!!!评论后请刷新页面。