生产者配置如下:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 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.xsd http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
<dubbo:application name="webserver"/>
<bean id="sayHelloImpl" class="com.sdp.dubbo.MyTest.SayHelloImpl"></bean>
<!--使用注册中心的dubbo-->
<!--这里我们就定义了一个注册中信,MultiCase该注册中心不需要加入任何jar包,但是该注册中心用的很少,不会在实际项目的开发中使用该注册市中心,
一般情况下,我们都会使用在软件开发的测试阶段使用该注册中中心,需要注意的是,该注册中心的访问是使用IP+端口,IP应在244.0.0.0~239.255.255.255
之间,端口的话,你就自己指定就行了,但是不能发生端口冲突的情况。
可以看出在这里使用了multicase协议访问
-->
<dubbo:registry address="multicast://224.2.3.4:45678"/>
<!--将生产者的劳动成功注册到MultiCast注册中心-->
<dubbo:service interface="com.sdp.dubbo.MyTest.SayHello" ref ="sayHelloImpl"/>
</beans>
消费者的配置如下:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 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.xsd http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
<dubbo:application name="webcustom"/>
<!--在消费者端注册注册中心,是为了从注册中心中拿取由生产者提供的功能(接口吧!)-->
<dubbo:registry address="multicast://224.2.3.4:45678"/>
<dubbo:reference id ="sayHello" interface="com.sdp.dubbo.MyTest.SayHello"/>
</beans>
启动时报错如下:
我的解决方案:
关闭虚拟网卡!
如果你的计算机装了vmware或者其它虚拟机软件,那么就很容易造成虚拟网卡混乱,笔者也不是很懂虚拟网卡,所以,我们直接将虚拟网卡关闭,即可。
步骤如下:
右击,我的电脑,点击 ————>管理 出现如下界面
以上是个人经验所得,希望对大家能有帮助!(修改完别忘了重启生产者0.0)