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”/> 添加一个log4j.properties文件,内容如下: log4j.rootLogger=INFO,A1 log4j.appender.A1=org.apache.log4j.ConsoleAppender log4j.appender.A1.layout=org.apache.log4j.PatternLayout 创建启动程序,如下: public class App { public static void main(String[] args) throws Exception{ ApplicationContext ac = new ClassPathXmlApplicationContext(“applicationContext.xml”); //挂起当前线程,如果没有改行代码,服务提供者进程会消亡,服务消费者就发现不了提供者了 Thread.currentThread().join(); } } 完成目录结构 启动程序 服务端启动成功~ zookeeper中也可以查看到相关信息 服务消费者 依赖和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 添加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”/> 添加一个log4j.properties文件,内容如下: log4j.rootLogger=INFO,A1 log4j.appender.A1=org.apache.log4j.ConsoleAppender log4j.appender.A1.layout=org.apache.log4j.PatternLayout 创建启动程序,访问服务 public class TestConsumer { public static void main(String[] args) { ApplicationContext ac = new ClassPathXmlApplicationContext(“applicationContext.xml”); 欢迎分享,转载请注明来源:内存溢出
1.添加相关依赖
评论列表(0条)