阿超
        >
        
webflux之webclient踩坑tablefield
     
    
    
    
    
    
        
任难任之事,要有力而无气;处难处之人,要有知而无言。——金缨
今天踩坑发现使用webclient发起请求
| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 
 | 
 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;
 
 
 
 
 
 
 @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);
 }
 
 }
 
 
 | 
然后是调用代码:
| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 
 | 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;
 
 
 
 
 
 
 @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说是mybatis的org.apache.ibatis.type.JdbcType找不到…
最后排查发现UserAccountDTO里有个字段加了注解com.baomidou.mybatisplus.annotation.TableField
而我在webflux项目中默认使用的
| 12
 3
 4
 5
 
 | <dependency><groupId>com.baomidou</groupId>
 <artifactId>mybatis-plus-boot-starter</artifactId>
 <scope>provided</scope>
 </dependency>
 
 | 
最后去掉TableField解决了