springboot dubbo配置

dubbo版本 2.6.2
需要额外引入

implementation “org.apache.curator:curator-framework:4.2.0” //dubbo依赖

  1. provider配置

resources新增文件 dubbo/privider.xml (xml来自官网示例)

<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:dubbo="http://dubbo.apache.org/schema/dubbo"
       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">
    <dubbo:application name="demo-provider"/>
    <dubbo:registry address="zookeeper://127.0.0.1:2181"/>
    <dubbo:protocol name="dubbo" port="20890"/>
    <dubbo:service interface="com.halo.mms.out.InformService" ref="informServiceImpl"/>
beans>
  1. consumer配置
    resources新增文件 dubbo/consumer.xml (xml来自官网示例)
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:dubbo="http://dubbo.apache.org/schema/dubbo"
       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">
    <dubbo:application name="demo-consumer"/>
    <dubbo:registry address="zookeeper://127.0.0.1:2181"/>
    <dubbo:reference id="infoService" check="false" interface="com.halo.mms.out.InformService"/>
beans>
  1. provider和consumer在启动类上加注解
@ImportResource({"classpath:/dubbo/provider.xml"})
@ImportResource({"classpath:/dubbo/consumer.xml"})

你可能感兴趣的:(java)