前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >webflux之webclient踩坑tablefield

webflux之webclient踩坑tablefield

作者头像
阿超
发布2024-02-10 09:08:07
750
发布2024-02-10 09:08:07
举报
文章被收录于专栏:快乐阿超快乐阿超

任难任之事,要有力而无气;处难处之人,要有知而无言。——金缨

今天踩坑发现使用webclient发起请求

代码语言:javascript
复制


import com.alibaba.nacos.common.utils.JacksonUtils;
import org.dromara.streamquery.stream.core.collection.Lists;
import org.springframework.stereotype.Service;
import org.springframework.web.reactive.function.client.WebClient;
import reactor.core.publisher.Mono;

import java.util.List;
import java.util.Objects;

/**
 * MallClient
 *
 * @author achao@apache.org
 */
@Service
public class MallClient {

    private final WebClient webClient;

    public MallClient(WebClient.Builder webClientBuilder) {
        this.webClient = webClientBuilder.baseUrl("http://mall-service").build();
    }

    public Mono<Boolean> incrementPointsByUserId(List<UserAccountDTO> accounts) {
        accounts.removeIf(account -> Objects.isNull(account.getPointsNum()) ||
                Objects.equals(account.getPointsNum(), 0L));
        if (Lists.isEmpty(accounts)) {
            return Mono.empty();
        }
        return webClient.post()
                .uri("/foo")
                .bodyValue(JacksonUtils.toJson(bar))
                .retrieve().bodyToMono(String.class)
                .map(str -> {
                    var node = JacksonUtils.toObj(str);
                    if (!JsonUtils.isResOk(node)) {
                        throw new ApiServerException("incrementPointsByUserId failed");
                    }
                    return true;
                })
                .doOnError(Throwable::printStackTrace);
    }

}

然后是调用代码:

代码语言:javascript
复制
import jakarta.annotation.Resource;
import org.dromara.streamquery.stream.core.collection.Lists;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import reactor.test.StepVerifier;

/**
 * MallClientTest
 *
 * @author achao@apache.org
 */
@SpringBootTest
class MallClientTest {

    @Resource
    private MallClient mallClient;

    @Test
    void incrementPointsByUserIdTest() {
        var userAccount = new UserAccountDTO();
        userAccount.setUserId(9052710354240385086L);
        userAccount.setPointsNum(100L);
        userAccount.setPointSceneType(PointSceneType.WORD_CHAIN);
        StepVerifier.create(mallClient.incrementPointsByUserId(
                        Lists.of(userAccount)))
                .expectNextMatches(result -> result.equals(true))
                .expectComplete()
                .verify();
    }

}

发现调用一直抛出java.lang.NoClassDefFoundError说是mybatisorg.apache.ibatis.type.JdbcType找不到…

最后排查发现UserAccountDTO里有个字段加了注解com.baomidou.mybatisplus.annotation.TableField

而我在webflux项目中默认使用的

代码语言:javascript
复制
<dependency>
    <groupId>com.baomidou</groupId>
    <artifactId>mybatis-plus-boot-starter</artifactId>
    <scope>provided</scope>
</dependency>

最后去掉TableField解决了

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2024-02-09,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档