Compare commits

..

1 Commits

Author SHA1 Message Date
yovinchen 98d1550af9 基于XML 2023-12-04 16:20:17 +08:00
8 changed files with 161 additions and 1 deletions

View File

@ -28,7 +28,7 @@
<dependency> <dependency>
<groupId>org.apache.zookeeper</groupId> <groupId>org.apache.zookeeper</groupId>
<artifactId>zookeeper</artifactId> <artifactId>zookeeper</artifactId>
<version>3.8.3</version> <version>3.8.0</version>
<exclusions> <exclusions>
<exclusion> <exclusion>
<groupId>io.netty</groupId> <groupId>io.netty</groupId>

View File

@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>dubbo-spring-xml-demo</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo</artifactId>
<version>3.1.6</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>5.3.25</version>
</dependency>
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-x-discovery</artifactId>
<version>5.2.0</version>
</dependency>
<dependency>
<groupId>org.apache.zookeeper</groupId>
<artifactId>zookeeper</artifactId>
<version>3.8.0</version>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,13 @@
package org.apache.dubbo.samples.api;
/**
* ClassName: GreetingsService
* Package: org.apache.dubbo.samples.api
*
* @author yovinchen
* @Create 2023/12/4 16:16
*/
public interface GreetingsService {
String sayHi(String name);
}

View File

@ -0,0 +1,27 @@
package org.apache.dubbo.samples.client;
import org.apache.dubbo.samples.api.GreetingsService;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import java.io.IOException;
/**
* ClassName: Application
* Package: org.apache.dubbo.samples.client
*
* @author yovinchen
* @Create 2023/12/4 16:18
*/
public class Application {
public static void main(String[] args) throws IOException {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("dubbo-demo-consumer.xml");
context.start();
GreetingsService greetingsService = (GreetingsService) context.getBean("greetingsService");
String message = greetingsService.sayHi("dubbo");
System.out.println("Receive result ======> " + message);
System.in.read();
System.exit(0);
}
}

View File

@ -0,0 +1,23 @@
package org.apache.dubbo.samples.provider;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import java.util.concurrent.CountDownLatch;
/**
* ClassName: Application
* Package: org.apache.dubbo.samples.provider
*
* @author yovinchen
* @Create 2023/12/4 16:18
*/
public class Application {
public static void main(String[] args) throws InterruptedException {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("dubbo-demo-provider.xml");
context.start();
// 挂起主线程防止退出
new CountDownLatch(1).await();
}
}

View File

@ -0,0 +1,17 @@
package org.apache.dubbo.samples.provider;
import org.apache.dubbo.samples.api.GreetingsService;
/**
* ClassName: GreetingsServiceImpl
* Package: org.apache.dubbo.samples.provider
*
* @author yovinchen
* @Create 2023/12/4 16:16
*/
public class GreetingsServiceImpl implements GreetingsService {
@Override
public String sayHi(String name) {
return "hi, " + name;
}
}

View File

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:dubbo="http://dubbo.apache.org/schema/dubbo"
xmlns:context="http://www.springframework.org/schema/context" xmlns="http://www.springframework.org/schema/beans"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://dubbo.apache.org/schema/dubbo http://dubbo.apache.org/schema/dubbo/dubbo.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<context:property-placeholder/>
<!-- 定义应用名 -->
<dubbo:application name="demo-provider"/>
<!-- 定义注册中心地址 -->
<dubbo:registry address="zookeeper://8.130.127.71:2181"/>
<!-- 定义订阅信息Dubbo 会在 Spring Context 中创建对应的 bean -->
<dubbo:reference id="greetingsService" interface="org.apache.dubbo.samples.api.GreetingsService"/>
</beans>

View File

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:dubbo="http://dubbo.apache.org/schema/dubbo"
xmlns:context="http://www.springframework.org/schema/context" xmlns="http://www.springframework.org/schema/beans"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://dubbo.apache.org/schema/dubbo http://dubbo.apache.org/schema/dubbo/dubbo.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<context:property-placeholder/>
<!-- 定义应用名 -->
<dubbo:application name="demo-provider"/>
<!-- 定义注册中心地址 -->
<dubbo:registry address="zookeeper://8.130.127.71:2181"/>
<!-- 定义实现类对应的 bean -->
<bean id="greetingsService" class="org.apache.dubbo.samples.provider.GreetingsServiceImpl"/>
<!-- 定义服务信息,引用上面的 bean -->
<dubbo:service interface="org.apache.dubbo.samples.api.GreetingsService" ref="greetingsService"/>
</beans>