softxiang opened a new issue #2215: 与spring结合使用时循环依赖导致事务失效问题
URL: https://github.com/apache/incubator-dubbo/issues/2215
 
 
   - [√] I have searched the 
[issues](https://github.com/apache/incubator-dubbo/issues) of this repository 
and believe that this is not a duplicate.
   - [√] I have checked the 
[FAQ](https://github.com/apache/incubator-dubbo/blob/master/FAQ.md) of this 
repository and believe that this is not a duplicate.
   
   ### Environment
   
   * Dubbo version: 2.5.7
   * Operating System version: win10
   * Java version: 1.8
   
   ### Step to reproduce this issue
   
   有A、B两个服务,相互依赖时会造成事务失效,简要代码如下:
   > AServiceImpl
   ```java
   @Service(interfaceClass=IAService.class,group="test",version="1.0.0")
   @Transactional
   public class AServiceImpl implements IAService {
       @Autowired
       private ITestService testService;
   
       @Autowired
       private IBService bService;
       @Override
       public void test(String string) {
           TestEntity testEntity = new TestEntity();
           testEntity.setTest("A-"+string);
           testEntity = testService.save(testEntity);
           if(!Objects.isNull(testEntity.getId())){
               throw new RuntimeException("AService test....a...");
           }
       }
   }
   ```
   > BServiceImpl
   ```java
   @Service(interfaceClass=IBService.class,group="test",version="1.0.0")
   @Transactional
   public class BServiceImpl implements IBService {
       @Autowired
       private ITestService testService;
   
       @Autowired
       private IAService aService;//相互引用,但实际并未使用
       @Override
       public void test(String string) {
           TestEntity testEntity = new TestEntity();
           testEntity.setTest("B-"+string);
           testEntity = testService.save(testEntity);
           if(!Objects.isNull(testEntity.getId())){
               throw new RuntimeException("BService test...b....");
           }
       }
   }
   ```
   > test
   ```java
   @RunWith(SpringRunner.class)
   @SpringBootTest
   public class SpringbootDubboDemoApplicationTests {
   
       @Autowired
       private ITestService testService;
   
       @Reference(group = "test", version = "1.0.0")
       private IAService iaService;
       @Reference(group = "test", version = "1.0.0")
       private IBService ibService;
   
       @Test
       public void  testDubbo(){
           System.out.println("start......");
           try {
               iaService.test("aaaa");
           }catch (Exception e){
               e.printStackTrace();
           }
           try {
               ibService.test("bbbbb");
           }catch (Exception e){
               e.printStackTrace();
           }
       }
   }
   ```
   
   ### Expected Result
   
   正常执行过后,事务应该回滚,数据库中没有保存数据
   
   ### Actual Result
   
   实际结果,a服务执行,数据库中存在记录
   
   A-aaaa 被插入数据库
   
   当注释掉A/B的循环依赖时,结果正常,数据库中没有数据
   
   
详细代码见:[https://github.com/softxiang/springboot-dubbo-demo](https://github.com/softxiang/springboot-dubbo-demo)
   
   另有一个问题如下:
   @Service(interfaceClass=IAService.class,group="test",version="1.0.0")
   @Transactional
   public class AServiceImpl implements IAService 
   
   此种情况定义了一个dubbo service,是否还需要spring扫描这个service 
看代码情况是不需要spring再做相应操作,但看网上很多文章包括issues中依然有人提类似问题 
[#2093](https://github.com/apache/incubator-dubbo/issues/2093)
   一个服务既是dubbo服务又是本地服务时,是否只需要注册为dubbo的service即可?
   
   @Autowired
   private IBService bService;
   
   是否会自动区分本地service调用 还是dubbo service?
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to