Spring Cloud Alibaba 2.2.0使用的多么
时间: 2024-05-29 12:09:39 浏览: 9
Spring Cloud Alibaba 2.2.0是一个相对较新的版本,于2020年11月发布。它引入了一些新的功能和改进,例如:
1. 支持Nacos 2.0和Sentinel 1.8版本。
2. 引入了新的Spring Cloud Alibaba Dubbo和RocketMQ Starter,使得使用Dubbo和RocketMQ变得更加容易。
3. 新增了Alibaba Cloud ACM配置中心的支持。
4. 增强了对Spring Cloud Gateway的支持,提供了更多的自定义选项。
5. 改进了Spring Cloud Alibaba的性能和稳定性。
总的来说,Spring Cloud Alibaba 2.2.0是一个可靠的版本,包含了一些新的功能和改进。如果你正在使用Spring Cloud Alibaba,建议升级到这个版本以获得最好的体验。
相关问题
idea spring cloud alibaba配置教程
Idea spring cloud alibaba配置教程如下:
1. 打开IntelliJ IDEA,创建一个Spring Boot项目。
2. 在pom.xml文件中添加以下依赖:
```
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
<version>2.2.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
<version>2.2.4.RELEASE</version>
</dependency>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-alibaba-seata</artifactId>
<version>2.2.0.RELEASE</version>
</dependency>
```
3. 在application.yml文件中添加配置信息:
```
server:
port: 8080
spring:
application:
name: service-a
cloud:
nacos:
discovery:
server-addr: localhost:8848
seata:
tx-service-group: my_test_tx_group
```
其中,server.port是指定应用的端口号,spring.application.name是指定应用的名称,nacos.discovery.server-addr是指定Nacos服务注册中心的地址,seata.tx-service-group是指定Seata的事务分组。
4. 在启动类上添加注解@EnableDiscoveryClient和@EnableFeignClients,表示启用Nacos服务发现和Feign客户端。
```
@SpringBootApplication
@EnableDiscoveryClient
@EnableFeignClients
public class ServiceAApplication {
public static void main(String[] args) {
SpringApplication.run(ServiceAApplication.class, args);
}
}
```
5. 配置Feign客户端接口,在接口上添加注解@FeignClient,并指定服务名称。
```
@FeignClient(name = "service-b")
public interface ServiceBClient {
@GetMapping(value = "/hello")
String hello();
}
```
6. 编写Controller类,在Controller类中使用Feign客户端调用其他服务。
```
@RestController
public class ServiceAController {
@Autowired
private ServiceBClient serviceBClient;
@GetMapping("/test")
public String test() {
return serviceBClient.hello();
}
}
```
7. 运行应用程序,访问http://localhost:8080/test,即可看到调用了ServiceB的结果。
以上就是Idea spring cloud alibaba配置教程的全部内容。
springboot + springcloud alibaba seata 使用TCC模式代码模板
以下是一个使用Spring Boot和Spring Cloud Alibaba Seata框架实现的TCC模式代码模板:
1. 创建一个Spring Boot项目,添加依赖:
```xml
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-seata</artifactId>
<version>2.2.0.RELEASE</version>
</dependency>
```
2. 配置Seata相关信息:
```yaml
spring:
application:
name: tcc-demo
seata:
enabled: true
application-id: ${spring.application.name}
tx-service-group: my_tx_group
service:
vgroup-mapping.my_tx_group: default
config:
type: nacos
nacos:
server-addr: localhost:8848
namespace: public
registry:
type: nacos
nacos:
server-addr: localhost:8848
namespace: public
storage:
type: db
db:
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql://localhost:3306/seata?useUnicode=true&characterEncoding=utf-8&useSSL=false
username: root
password: root
```
3. 创建一个TCC接口:
```java
public interface TccService {
@TccTransaction(confirmMethod = "confirm", cancelMethod = "cancel")
boolean tryMethod(String businessKey, String param);
boolean confirm(String businessKey, String param);
boolean cancel(String businessKey, String param);
}
```
4. 实现TCC接口:
```java
@Service
public class TccServiceImpl implements TccService {
@Resource
private TccMapper tccMapper;
@Override
public boolean tryMethod(String businessKey, String param) {
TccEntity tccEntity = new TccEntity();
tccEntity.setBusinessKey(businessKey);
tccEntity.setParam(param);
return tccMapper.insert(tccEntity) > 0;
}
@Override
public boolean confirm(String businessKey, String param) {
return true;
}
@Override
public boolean cancel(String businessKey, String param) {
return tccMapper.deleteByBusinessKey(businessKey) > 0;
}
}
```
5. 配置TCC事务管理器:
```java
@Configuration
public class SeataConfiguration {
@Bean
public GlobalTransactionScanner globalTransactionScanner() {
return new GlobalTransactionScanner("tcc-demo", "my_tx_group");
}
@Bean
public TccTransactionAspect tccTransactionAspect() {
return new TccTransactionAspect();
}
@Bean
public DataSourceProxy dataSourceProxy(DataSource dataSource) {
return new DataSourceProxy(dataSource);
}
}
```
6. 测试TCC接口:
```java
@RestController
@RequestMapping("/tcc")
public class TccController {
@Resource
private TccService tccService;
@PostMapping("/try")
public boolean tryMethod(@RequestParam String businessKey, @RequestParam String param) {
return tccService.tryMethod(businessKey, param);
}
}
```
以上是一个简单的TCC模式代码模板,可以根据实际业务需求进行修改和扩展。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![jar](https://img-home.csdnimg.cn/images/20210720083455.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)