【发布时间】:2019-10-07 08:51:29
【问题描述】:
我的应用程序基于 Spring 反应式 mysql。当我尝试从 mysql db 获取数据时,出现错误“org.springframework.core.convert.ConverterNotFoundException:找不到能够从类型 [java.nio.HeapByteBuffer] 转换为类型 [java.util.UUID] 的转换器”
我尝试将转换器添加到实现 WebFluxConfigurer 的 WebConfig,但是当 Spring 查找转换器时,由于 ByteBuffer 而不是 HeapByteBuffer(此类受保护,扩展 ByteBuffer)而无法找到。
@Configuration
@EnableWebFlux
public class WebConfig implements WebFluxConfigurer {
@Override
public void addFormatters(FormatterRegistry registry) {
registry.addConverter(new ByteBufferToUUIDConverter());
}
}
和转换的伪代码
public class ByteBufferToUUIDConverter implements Converter<ByteBuffer, UUID>, ConditionalConverter {
private Logger logger = LogManager.getLogger(ByteBufferToUUIDConverter.class);
@Override
public UUID convert(ByteBuffer source) {
return null;
}
@Override
public boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType) {
logger.debug(":TypeDescriptor " + sourceType + ", " + targetType);
return true;
}
}
【问题讨论】:
标签: spring converters