dubbo 学习体验

dubbo学习的xml配置和注解配置

  1. 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="${dubbo.application.name}" logger="slf4j"/>
    
    	<!-- 使用multicast广播注册中心暴露服务地址 -->
    	<dubbo:registry address="${dubbo.registry.address}" file="${dubbo.registry.file}"/>
    
    	<!-- 用dubbo协议在20880端口暴露服务 -->
    	<dubbo:protocol name="dubbo" port="${dubbo.protocol.port}"/>
    
    
    	<dubbo:provider delay="-1" timeout="${dubbo.provider.timeout}" protocol="dubbo"/>
    
    	<dubbo:consumer retries="0" timeout="60000"/>
    </beans>
    ###################以上是spring配置provider.xml######################################
    
    
    ###############以下是spring配置dubbo-service.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">
    
    // 对外提供服务,ref为接口的实现类,采用的是Spring的默认beanName,通讯协议protocol为dubbo
    
        <dubbo:service interface="com.zihe.loan.user.service.IUserService" ref="userServiceImpl" version="${dubbo.application.version}" protocol="dubbo"/>
        <dubbo:service interface="com.zihe.loan.user.service.IUserBlackWhiteListService" ref="userBlackWhiteListServiceImpl" version="${dubbo.application.version}" protocol="dubbo"/>
    
    </beans>
    
    
    
    
    
    
    ###############以下是引用该服务#############################
    
    <?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="http://www.springframework.org/schema/beans"
           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:reference id="iUserService" interface="com.zihe.loan.user.service.IUserService" version="${dubbo.application.version}" protocol="dubbo" check="false"/>
        <dubbo:reference id="iUserBlackWhiteListService" interface="com.zihe.loan.user.service.IUserBlackWhiteListService" version="${dubbo.application.version}" protocol="dubbo" check="false"/>
        <dubbo:reference id="iAuthenticationService" interface="com.zihe.loan.user.service.IAuthenticationService" version="${dubbo.application.version}" protocol="dubbo" check="false"/>
    
    
    
    </beans>
    
    
    2.注解配置   

dubbo服务之间的调用通过@Reference注解来引用服务

 

猜你喜欢

转载自blog.csdn.net/iCopper_/article/details/88984141