IntelliJ IDEA(2019)Maven聚合工程实现dubbo入门案例,java注解处理器工作原理及过程

IntelliJ IDEA(2019)Maven聚合工程实现dubbo入门案例,java注解处理器工作原理及过程,第1张

IntelliJ IDEA(2019)Maven聚合工程实现dubbo入门案例,java注解处理器工作原理及过程

2.5.3

spring

org.springframework

com.github.sgroschupf

zkclient

0.1

2.接口实现

引入了commons模块的依赖,我们就可以创建公共接口的实现类了,具体如下:

public class UserServiceImpl implements UserService {

@Override

public String sayHello(String msg) {

System.out.println(“服务端接收:”+msg);

return “你好啊”;

}

}

3.相关配置

创建spring的配置文件,如下:

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

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://www.springframework.org/schema/context

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

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

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

address=“zk00:2181,zk01:2181,zk02:2181” />

group=“dubbo” version=“1.0.0” timeout=“3000”/>

4.添加日志文件

添加一个log4j.properties文件,内容如下:

log4j.rootLogger=INFO,A1

log4j.appender.A1=org.apache.log4j.ConsoleAppender

log4j.appender.A1.layout=org.apache.log4j.PatternLayout

5.启动服务

创建启动程序,如下:

public class App {

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

ApplicationContext ac = new ClassPathXmlApplicationContext(“applicationContext.xml”);

//挂起当前线程,如果没有改行代码,服务提供者进程会消亡,服务消费者就发现不了提供者了

Thread.currentThread().join();

}

}

完成目录结构

启动程序

服务端启动成功~

zookeeper中也可以查看到相关信息

服务消费者


1.添加相关依赖

依赖和provider差不多,具体如下:

com.dpb

dubbo-commos

1.0-SNAPSHOT

org.springframework

spring-context

4.3.21.RELEASE

org.slf4j

slf4j-log4j12

1.7.25

com.alibaba

dubbo

2.5.3

spring

org.springframework

com.github.sgroschupf

zkclient

0.1

2.配置配置文件

添加spring的配置文件,配置dubbo消费者的相关信息

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

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

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://www.springframework.org/schema/context

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

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

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

address=“zk00:2181,zk01:2181,zk02:2181” />

group=“dubbo” version=“1.0.0” timeout=“3000”/>

3.添加日志文件

添加一个log4j.properties文件,内容如下:

log4j.rootLogger=INFO,A1

log4j.appender.A1=org.apache.log4j.ConsoleAppender

log4j.appender.A1.layout=org.apache.log4j.PatternLayout

4.访问服务

创建启动程序,访问服务

public class TestConsumer {

public static void main(String[] args) {

ApplicationContext ac = new ClassPathXmlApplicationContext(“applicationContext.xml”);

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5686972.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-17
下一篇 2022-12-17

发表评论

登录后才能评论

评论列表(0条)

保存