pom 中尽量排除 slf4j
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>5.3.6</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>dubbo</artifactId>
<version>2.6.6</version>
</dependency>
<dependency>
<groupId>服务端项目组</groupId>
<artifactId>服务端项目名</artifactId>
<version>版本</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
</exclusions>
</dependency>
public class Consumer {
public static void main(String[] args) throws Exception {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("consumer.xml");
context.start();
ProviderService providerService =(ProviderService)context.getBean("providerService");
String hello = providerService.SayHello("hello");
System.out.println( hello ); // 显示调用结果
}
}
consumer.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:dubbo="http://dubbo.apache.org/schema/dubbo"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.3.xsd http://dubbo.apache.org/schema/dubbo http://dubbo.apache.org/schema/dubbo/dubbo.xsd">
<!-- 消费方应用名,用于计算依赖关系,不是匹配条件,不要与提供方一样 -->
<dubbo:application name="consumer" owner="sihai"/>
<!--点对点的方式-->
<dubbo:registry address="N/A" />
<dubbo:protocol name="dubbo" port="8005" />
<!-- 生成远程服务代理,可以和本地bean一样使用demoService -->
<dubbo:reference id="providerService" version="1.0.0"
interface="com.www.service.ProviderService"
url="dubbo://127.0.0.1:8005/com.www.service.ProviderService" />
</beans>
注意版本号不然会找不到报错
Caused by: com.alibaba.dubbo.remoting.RemotingException: com.alibaba.dubbo.remoting.RemotingException: Not found exported service xxxx
may be version or group mismatch