关于 spring cloud alibaba 2.2.0 引入 sentinel 找不到 WebCallBackManager

 
        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
        </dependency>

        <dependency>
            <groupId>com.alibaba.csp</groupId>
            <artifactId>sentinel-web-servlet</artifactId>
        </dependency>
@Configuration
public class SentinelConfig {
    public SentinelConfig(){
        WebCallbackManager.setUrlBlockHandler(new UrlBlockHandler() {
            @Override
            public void blocked(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, BlockException e) throws IOException {
                R error = R.error(BizCodeEnum.TOO_MANY_REQUEST.getCode(), BizCodeEnum.TOO_MANY_REQUEST.getMsg());
                httpServletResponse.setCharacterEncoding("UTF-8");
                httpServletResponse.setContentType("application/json");
                httpServletResponse.getWriter().write(JSON.toJSONString(error));
            }
        });
    }
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Spring Boot 项目转换为 Spring Cloud Alibaba 项目,需要进行以下步骤: 1. 添加 Spring Cloud Alibaba 的依赖: 在 `pom.xml` 文件中添加以下依赖: ```xml <dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId> <version>2.2.0.RELEASE</version> </dependency> ``` 这里以 Nacos 为例,如果你使用其他的注册中心,可以根据相应的文档进行配置。 2. 配置注册中心地址: 在 `application.yaml` 文件中添加以下配置: ```yaml spring: cloud: nacos: discovery: server-addr: localhost:8848 ``` 这里的地址需要根据你实际使用的注册中心地址进行修改。 3. 配置服务提供者: 在 Spring Boot 项目中,我们可以使用 `@RestController` 注解来实现 RESTful API。在 Spring Cloud Alibaba 中,我们可以使用 `@DubboService` 注解来实现服务提供者。 首先,需要在 `pom.xml` 文件中添加以下依赖: ```xml <dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-starter-dubbo</artifactId> <version>2.2.0.RELEASE</version> </dependency> ``` 然后,在服务提供者的实现类上添加 `@DubboService` 注解,示例代码如下: ```java @Service @DubboService public class UserServiceImpl implements UserService { // ... } ``` 4. 配置服务消费者: 在 Spring Boot 项目中,我们可以使用 `RestTemplate` 进行服务调用。在 Spring Cloud Alibaba 中,我们可以使用 `@Reference` 注解来实现服务消费者。 首先,需要在 `pom.xml` 文件中添加以下依赖: ```xml <dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-starter-dubbo</artifactId> <version>2.2.0.RELEASE</version> </dependency> ``` 然后,在服务消费者中,使用 `@Reference` 注解来注入 Dubbo 服务接口,示例代码如下: ```java @RestController public class UserController { @Reference private UserService userService; // ... } ``` 5. 运行项目: 在完成以上步骤后,可以启动项目,并在注册中心中查看服务是否注册成功。如果服务注册成功,就可以使用服务消费者来调用服务提供者提供的接口了。 以上是将 Spring Boot 项目转换为 Spring Cloud Alibaba 项目的大致步骤,具体实现还需要根据项目实际情况进行调整。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值