分布式事物 seata
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
package com.czg.service.account.service.impl;
|
||||
|
||||
import com.czg.account.entity.UserInfo;
|
||||
import com.czg.account.service.TestService;
|
||||
import com.czg.account.service.UserInfoService;
|
||||
import com.czg.resp.CzgResult;
|
||||
import com.czg.system.dto.SysParamsDTO;
|
||||
import com.czg.system.service.SysParamsService;
|
||||
import io.seata.spring.annotation.GlobalTransactional;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.apache.dubbo.config.annotation.DubboReference;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* @author GYJoker
|
||||
*/
|
||||
@Service
|
||||
public class TestServiceImpl implements TestService {
|
||||
|
||||
@Resource
|
||||
private UserInfoService userInfoService;
|
||||
|
||||
@DubboReference
|
||||
private SysParamsService sysParamsService;
|
||||
|
||||
@Override
|
||||
@GlobalTransactional
|
||||
public String insertData() {
|
||||
|
||||
SysParamsDTO paramsDTO = new SysParamsDTO();
|
||||
paramsDTO.setParamCode("test22222");
|
||||
CzgResult<String> czgResult = sysParamsService.insertParams(paramsDTO);
|
||||
System.out.println(czgResult);
|
||||
if (czgResult.getCode() != 200){
|
||||
throw new RuntimeException("insert params error");
|
||||
}
|
||||
|
||||
UserInfo userInfo = new UserInfo();
|
||||
userInfo.setPhone("18812345678");
|
||||
userInfo.setPassword("123456");
|
||||
|
||||
userInfoService.save(userInfo);
|
||||
|
||||
|
||||
|
||||
|
||||
return "insert data success";
|
||||
}
|
||||
}
|
||||
@@ -80,6 +80,11 @@
|
||||
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.seata</groupId>
|
||||
<artifactId>seata-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-bootstrap</artifactId>
|
||||
|
||||
Reference in New Issue
Block a user