springboot整合dubbo加上事务注解启动报错的问题

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/bpqdwo/article/details/80217103

springboot整合dubbo加上事务注解启动报错的问题

如果使用以下方式
在其实现类中加入了事务注解

@Reference(version = "1.0.0", timeout = 30000)
    private ShopService shopService;
@Service(version = "1.0.0")
public class OrderFoodServiceImpl implements OrderFoodService {

则启动时就会报错,提示 无法引入ShopService这个类

application.yml 配置


server:
  port: 8083
spring:
 dubbo:
    application:
      name: com.deng
    registry:
      address: zookeeper://36.155.111.35:2181
    protocol:
      name: dubbo
      port: 20880
    scan: com.deng.dubbo

改之前

现在应该采用xml方式暴露 服务
只要将 服务暴露 发现 改为 这种方式即可。
dubbo-service.xml

<?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:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:dubbo="http://code.alibabatech.com/schema/dubbo" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd
    http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.2.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.2.xsd
    http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd
    http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.2.xsd">
    <!-- 声明需要暴露的服务接口 -->
    <dubbo:service interface="com.service.OrderService" ref="orderServiceImpl"  timeout="300000"/>
    <dubbo:service interface="com.service.ShopService" ref="shopService"  timeout="300000"/>
</beans>

同理。只要将服务暴露 和 发现 都用这种方式 就可以用事务注解了。

如果有更好的办法,希望大家可以提出来。

猜你喜欢

转载自blog.csdn.net/bpqdwo/article/details/80217103