2.3、XML方式
打开dubbo-demo-xml,目录结构如图:
打开服务提供者的Application,源码如下:
public class Application {
/**
* In order to make sure multicast registry works, need to specify '-Djava.net.preferIPv4Stack=true' before
* launch the application
*/
public static void main(String[] args) throws Exception {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("spring/dubbo-provider.xml");
context.start();
System.in.read();
}
}
找到对应的dubbo-provider.xml,修改注册中心地址:
<dubbo:registry address="zookeeper://192.168.200.1:2181" />
打开服务消费者的Application,源码如下:
public class Application {
/**
* In order to make sure multicast registry works, need to specify '-Djava.net.preferIPv4Stack=true' before
* launch the application
*/
public static void main(String[] args) {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("spring/dubbo-consumer.xml");
context.start();
DemoService demoService = context.getBean("demoService", DemoService.class);
String hello = demoService.sayHello("world");
System.out.println("result: " + hello);
}
}
修改对应的dubbo-consumer.xml,
<dubbo:registry address="zookeeper://192.168.200.1:2181"/>
启动服务提供者的Application,如下:
"D:\Program Files\Java\jdk1.8.0_111\bin\java.exe" "-javaagent:D:\Program Files\JetBrains\IntelliJ IDEA 2018.2.6\lib\idea_rt.jar=54386:D:\Program Files\JetBrains\IntelliJ IDEA 2018.2.6\bin" -Dfile.encoding=UTF-8 -classpath "D:\Program Files\Java\jdk1.8.0_111\jre\lib\charsets.jar;D:\Program Files\Java\jdk1.8.0_111\jre\lib\deploy.jar;D:\Program Files\Java\jdk1.8.0_111\jre\lib\ext\access-bridge-64.jar;D:\Program Files\Java\jdk1.8.0_111\jre\lib\ext\cldrdata.jar;D:\Program Files\Java\jdk1.8.0_111\jre\lib\ext\dnsns.jar;D:\Program Files\Java\jdk1.8.0_111\jre\lib\ext\jaccess.jar;D:\Program Files\Java\jdk1.8.0_111\jre\lib\ext\jfxrt.jar;D:\Program Files\Java\jdk1.8.0_111\jre\lib\ext\localedata.jar;D:\Program Files\Java\jdk1.8.0_111\jre\lib\ext\nashorn.jar;D:\Program Files\Java\jdk1.8.0_111\jre\lib\ext\sunec.jar;D:\Program Files\Java\jdk1.8.0_111\jre\lib\ext\sunjce_provider.jar;D:\Program Files\Java\jdk1.8.0_111\jre\lib\ext\sunmscapi.jar;D:\Program Files\Java\jdk1.8.0_111\jre\lib\ext\sunpkcs11.jar;D:\Program Files\Java\jdk1.8.0_111\jre\lib\ext\zipfs.jar;D:\Program Files\Java\jdk1.8.0_111\jre\lib\javaws.jar;D:\Program Files\Java\jdk1.8.0_111\jre\lib\jce.jar;D:\Program Files\Java\jdk1.8.0_111\jre\lib\jfr.jar;D:\Program Files\Java\jdk1.8.0_111\jre\lib\jfxswt.jar;D:\Program Files\Java\jdk1.8.0_111\jre\lib\jsse.jar;D:\Program Files\Java\jdk1.8.0_111\jre\lib\management-agent.jar;D:\Program Files\Java\jdk1.8.0_111\jre\lib\plugin.jar;D:\Program Files\Java\jdk1.8.0_111\jre\lib\resources.jar;D:\Program Files\Java\jdk1.8.0_111\jre\lib\rt.jar;D:\IdeaProjects\incubator-dubbo\dubbo-demo\dubbo-demo-xml\dubbo-demo-xml-provider\target\classes;D:\IdeaProjects\incubator-dubbo\dubbo-demo\dubbo-demo-interface\target\classes;D:\IdeaProjects\incubator-dubbo\dubbo-config\dubbo-config-spring\target\classes;D:\IdeaProjects\incubator-dubbo\dubbo-config\dubbo-config-api\target\classes;D:\IdeaProjects\incubator-dubbo\dubbo-monitor\dubbo-monitor-api\target\classes;D:\mavenrepository\com\alibaba\middleware\metrics-core-api\2.0.1\metrics-core-api-2.0.1.jar;D:\mavenrepository\com\alibaba\middleware\metrics-core-impl\2.0.1\metrics-core-impl-2.0.1.jar;D:\mavenrepository\com\alibaba\middleware\metrics-common\2.0.1\metrics-common-2.0.1.jar;D:\IdeaProjects\incubator-dubbo\dubbo-filter\dubbo-filter-validation\target\classes;D:\mavenrepository\javax\validation\validation-api\1.1.0.Final\validation-api-1.1.0.Final.jar;D:\IdeaProjects\incubator-dubbo\dubbo-filter\dubbo-filter-cache\target\classes;D:\mavenrepository\javax\cache\cache-api\1.0.0\cache-api-1.0.0.jar;D:\mavenrepository\org\springframework\spring-beans\4.3.16.RELEASE\spring-beans-4.3.16.RELEASE.jar;D:\mavenrepository\org\springframework\spring-core\4.3.16.RELEASE\spring-core-4.3.16.RELEASE.jar;D:\mavenrepository\org\springframework\spring-web\4.3.16.RELEASE\spring-web-4.3.16.RELEASE.jar;D:\mavenrepository\org\springframework\spring-aop\4.3.16.RELEASE\spring-aop-4.3.16.RELEASE.jar;D:\mavenrepository\org\springframework\spring-context\4.3.16.RELEASE\spring-context-4.3.16.RELEASE.jar;D:\mavenrepository\org\springframework\spring-expression\4.3.16.RELEASE\spring-expression-4.3.16.RELEASE.jar;D:\IdeaProjects\incubator-dubbo\dubbo-rpc\dubbo-rpc-injvm\target\classes;D:\IdeaProjects\incubator-dubbo\dubbo-registry\dubbo-registry-zookeeper\target\classes;D:\IdeaProjects\incubator-dubbo\dubbo-registry\dubbo-registry-api\target\classes;D:\IdeaProjects\incubator-dubbo\dubbo-cluster\target\classes;D:\mavenrepository\org\yaml\snakeyaml\1.20\snakeyaml-1.20.jar;D:\IdeaProjects\incubator-dubbo\dubbo-remoting\dubbo-remoting-zookeeper\target\classes;D:\mavenrepository\org\apache\curator\curator-recipes\4.0.1\curator-recipes-4.0.1.jar;D:\mavenrepository\org\apache\curator\curator-framework\4.0.1\curator-framework-4.0.1.jar;D:\mavenrepository\org\apache\curator\curator-client\4.0.1\curator-client-4.0.1.jar;D:\mavenrepository\com\google\guava\guava\20.0\guava-20.0.jar;D:\mavenrepository\org\apache\zookeeper\zookeeper\3.4.13\zookeeper-3.4.13.jar;D:\mavenrepository\org\slf4j\slf4j-api\1.7.25\slf4j-api-1.7.25.jar;D:\mavenrepository\org\slf4j\slf4j-log4j12\1.7.25\slf4j-log4j12-1.7.25.jar;D:\mavenrepository\jline\jline\0.9.94\jline-0.9.94.jar;D:\mavenrepository\org\apache\yetus\audience-annotations\0.5.0\audience-annotations-0.5.0.jar;D:\IdeaProjects\incubator-dubbo\dubbo-registry\dubbo-registry-multicast\target\classes;D:\IdeaProjects\incubator-dubbo\dubbo-rpc\dubbo-rpc-dubbo\target\classes;D:\IdeaProjects\incubator-dubbo\dubbo-rpc\dubbo-rpc-api\target\classes;D:\IdeaProjects\incubator-dubbo\dubbo-remoting\dubbo-remoting-api\target\classes;D:\IdeaProjects\incubator-dubbo\dubbo-container\dubbo-container-api\target\classes;D:\IdeaProjects\incubator-dubbo\dubbo-configcenter\dubbo-configcenter-api\target\classes;D:\IdeaProjects\incubator-dubbo\dubbo-remoting\dubbo-remoting-netty4\target\classes;D:\mavenrepository\io\netty\netty-all\4.1.25.Final\netty-all-4.1.25.Final.jar;D:\IdeaProjects\incubator-dubbo\dubbo-serialization\dubbo-serialization-hessian2\target\classes;D:\IdeaProjects\incubator-dubbo\dubbo-serialization\dubbo-serialization-api\target\classes;D:\mavenrepository\com\alibaba\fastjson\1.2.46\fastjson-1.2.46.jar;D:\mavenrepository\com\esotericsoftware\kryo\4.0.1\kryo-4.0.1.jar;D:\mavenrepository\com\esotericsoftware\reflectasm\1.11.3\reflectasm-1.11.3.jar;D:\mavenrepository\org\ow2\asm\asm\5.0.4\asm-5.0.4.jar;D:\mavenrepository\com\esotericsoftware\minlog\1.3.0\minlog-1.3.0.jar;D:\mavenrepository\de\javakaffee\kryo-serializers\0.42\kryo-serializers-0.42.jar;D:\mavenrepository\de\ruedigermoeller\fst\2.48-jdk-6\fst-2.48-jdk-6.jar;D:\mavenrepository\com\fasterxml\jackson\core\jackson-core\2.8.6\jackson-core-2.8.6.jar;D:\mavenrepository\com\cedarsoftware\java-util\1.9.0\java-util-1.9.0.jar;D:\mavenrepository\com\cedarsoftware\json-io\2.5.1\json-io-2.5.1.jar;D:\mavenrepository\com\alibaba\hessian-lite\3.2.5\hessian-lite-3.2.5.jar;D:\IdeaProjects\incubator-dubbo\dubbo-configcenter\dubbo-configcenter-zookeeper\target\classes;D:\IdeaProjects\incubator-dubbo\dubbo-metadata-report\dubbo-metadata-report-zookeeper\target\classes;D:\IdeaProjects\incubator-dubbo\dubbo-metadata-report\dubbo-metadata-report-api\target\classes;D:\IdeaProjects\incubator-dubbo\dubbo-metadata-report\dubbo-metadata-definition\target\classes;D:\mavenrepository\com\google\code\gson\gson\2.8.5\gson-2.8.5.jar;D:\IdeaProjects\incubator-dubbo\dubbo-metadata-report\dubbo-metadata-report-redis\target\classes;D:\mavenrepository\redis\clients\jedis\2.9.0\jedis-2.9.0.jar;D:\mavenrepository\org\apache\commons\commons-pool2\2.4.2\commons-pool2-2.4.2.jar;D:\IdeaProjects\incubator-dubbo\dubbo-plugin\dubbo-qos\target\classes;D:\IdeaProjects\incubator-dubbo\dubbo-common\target\classes;D:\mavenrepository\commons-logging\commons-logging\1.2\commons-logging-1.2.jar;D:\mavenrepository\log4j\log4j\1.2.16\log4j-1.2.16.jar;D:\mavenrepository\org\javassist\javassist\3.20.0-GA\javassist-3.20.0-GA.jar;D:\mavenrepository\org\objenesis\objenesis\2.6\objenesis-2.6.jar" org.apache.dubbo.demo.provider.Application
[06/04/19 16:16:38:839 GMT+08:00] main INFO support.ClassPathXmlApplicationContext: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@123772c4: startup date [Sat Apr 06 16:16:38 GMT+08:00 2019]; root of context hierarchy
[06/04/19 16:16:38:977 GMT+08:00] main INFO xml.XmlBeanDefinitionReader: Loading XML bean definitions from class path resource [spring/dubbo-provider.xml]
[06/04/19 16:16:39:372 GMT+08:00] main INFO logger.LoggerFactory: using logger: org.apache.dubbo.common.logger.log4j.Log4jLoggerAdapter
[06/04/19 16:16:40:182 GMT+08:00] main INFO config.AbstractConfig: [DUBBO] The service ready on spring started. service: org.apache.dubbo.demo.DemoService, dubbo version: , current host: 192.168.200.1
[06/04/19 16:16:40:297 GMT+08:00] main INFO utils.Compatibility: Running in ZooKeeper 3.4.x compatibility mode
[06/04/19 16:16:40:335 GMT+08:00] main INFO imps.CuratorFrameworkImpl: Starting
[06/04/19 16:16:40:343 GMT+08:00] main INFO zookeeper.ZooKeeper: Client environment:zookeeper.version=3.4.13-2d71af4dbe22557fda74f9a9b4309b15a7487f03, built on 06/29/2018 00:39 GMT
[06/04/19 16:16:40:343 GMT+08:00] main INFO zookeeper.ZooKeeper: Client environment:host.name=LAPTOP-JTFKJ809
[06/04/19 16:16:40:343 GMT+08:00] main INFO zookeeper.ZooKeeper: Client environment:java.version=1.8.0_111
[06/04/19 16:16:40:343 GMT+08:00] main INFO zookeeper.ZooKeeper: Client environment:java.vendor=Oracle Corporation
[06/04/19 16:16:40:343 GMT+08:00] main INFO zookeeper.ZooKeeper: Client environment:java.home=D:\Program Files\Java\jdk1.8.0_111\jre
[06/04/19 16:16:40:343 GMT+08:00] main INFO zookeeper.ZooKeeper: Client environment:java.class.path=D:\Program Files\Java\jdk1.8.0_111\jre\lib\charsets.jar;D:\Program Files\Java\jdk1.8.0_111\jre\lib\deploy.jar;D:\Program Files\Java\jdk1.8.0_111\jre\lib\ext\access-bridge-64.jar;D:\Program Files\Java\jdk1.8.0_111\jre\lib\ext\cldrdata.jar;D:\Program Files\Java\jdk1.8.0_111\jre\lib\ext\dnsns.jar;D:\Program Files\Java\jdk1.8.0_111\jre\lib\ext\jaccess.jar;D:\Program Files\Java\jdk1.8.0_111\jre\lib\ext\jfxrt.jar;D:\Program Files\Java\jdk1.8.0_111\jre\lib\ext\localedata.jar;D:\Program Files\Java\jdk1.8.0_111\jre\lib\ext\nashorn.jar;D:\Program Files\Java\jdk1.8.0_111\jre\lib\ext\sunec.jar;D:\Program Files\Java\jdk1.8.0_111\jre\lib\ext\sunjce_provider.jar;D:\Program Files\Java\jdk1.8.0_111\jre\lib\ext\sunmscapi.jar;D:\Program Files\Java\jdk1.8.0_111\jre\lib\ext\sunpkcs11.jar;D:\Program Files\Java\jdk1.8.0_111\jre\lib\ext\zipfs.jar;D:\Program Files\Java\jdk1.8.0_111\jre\lib\javaws.jar;D:\Program Files\Java\jdk1.8.0_111\jre\lib\jce.jar;D:\Program Files\Java\jdk1.8.0_111\jre\lib\jfr.jar;D:\Program Files\Java\jdk1.8.0_111\jre\lib\jfxswt.jar;D:\Program Files\Java\jdk1.8.0_111\jre\lib\jsse.jar;D:\Program Files\Java\jdk1.8.0_111\jre\lib\management-agent.jar;D:\Program Files\Java\jdk1.8.0_111\jre\lib\plugin.jar;D:\Program Files\Java\jdk1.8.0_111\jre\lib\resources.jar;D:\Program Files\Java\jdk1.8.0_111\jre\lib\rt.jar;D:\IdeaProjects\incubator-dubbo\dubbo-demo\dubbo-demo-xml\dubbo-demo-xml-provider\target\classes;D:\IdeaProjects\incubator-dubbo\dubbo-demo\dubbo-demo-interface\target\classes;D:\IdeaProjects\incubator-dubbo\dubbo-config\dubbo-config-spring\target\classes;D:\IdeaProjects\incubator-dubbo\dubbo-config\dubbo-config-api\target\classes;D:\IdeaProjects\incubator-dubbo\dubbo-monitor\dubbo-monitor-api\target\classes;D:\mavenrepository\com\alibaba\middleware\metrics-core-api\2.0.1\metrics-core-api-2.0.1.jar;D:\mavenrepository\com\alibaba\middleware\metrics-core-impl\2.0.1\metrics-core-impl-2.0.1.jar;D:\mavenrepository\com\alibaba\middleware\metrics-common\2.0.1\metrics-common-2.0.1.jar;D:\IdeaProjects\incubator-dubbo\dubbo-filter\dubbo-filter-validation\target\classes;D:\mavenrepository\javax\validation\validation-api\1.1.0.Final\validation-api-1.1.0.Final.jar;D:\IdeaProjects\incubator-dubbo\dubbo-filter\dubbo-filter-cache\target\classes;D:\mavenrepository\javax\cache\cache-api\1.0.0\cache-api-1.0.0.jar;D:\mavenrepository\org\springframework\spring-beans\4.3.16.RELEASE\spring-beans-4.3.16.RELEASE.jar;D:\mavenrepository\org\springframework\spring-core\4.3.16.RELEASE\spring-core-4.3.16.RELEASE.jar;D:\mavenrepository\org\springframework\spring-web\4.3.16.RELEASE\spring-web-4.3.16.RELEASE.jar;D:\mavenrepository\org\springframework\spring-aop\4.3.16.RELEASE\spring-aop-4.3.16.RELEASE.jar;D:\mavenrepository\org\springframework\spring-context\4.3.16.RELEASE\spring-context-4.3.16.RELEASE.jar;D:\mavenrepository\org\springframework\spring-expression\4.3.16.RELEASE\spring-expression-4.3.16.RELEASE.jar;D:\IdeaProjects\incubator-dubbo\dubbo-rpc\dubbo-rpc-injvm\target\classes;D:\IdeaProjects\incubator-dubbo\dubbo-registry\dubbo-registry-zookeeper\target\classes;D:\IdeaProjects\incubator-dubbo\dubbo-registry\dubbo-registry-api\target\classes;D:\IdeaProjects\incubator-dubbo\dubbo-cluster\target\classes;D:\mavenrepository\org\yaml\snakeyaml\1.20\snakeyaml-1.20.jar;D:\IdeaProjects\incubator-dubbo\dubbo-remoting\dubbo-remoting-zookeeper\target\classes;D:\mavenrepository\org\apache\curator\curator-recipes\4.0.1\curator-recipes-4.0.1.jar;D:\mavenrepository\org\apache\curator\curator-framework\4.0.1\curator-framework-4.0.1.jar;D:\mavenrepository\org\apache\curator\curator-client\4.0.1\curator-client-4.0.1.jar;D:\mavenrepository\com\google\guav