JDK8中JPA使用LocalDate, LocalTime 和 LocalDateTime会报反序列错误解决方法

spring-boot在使用spring-data-jpa时,如果需要对LocalDate、LocalDateTime等在jsr310中定义的新日期类进行支持,需要在启动类或带有@Configuration的类上加入以下注解:
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.cloud.stream.annotation.StreamListener;
import org.springframework.data.jpa.convert.threeten.Jsr310JpaConverters;

@EntityScan(
        basePackageClasses = {ServicePromotionApplication.class, Jsr310JpaConverters.class}
)
public class ServicePromotionApplication {
 public static void main(String[] args) {
        SpringApplication.run(ServicePromotionApplication.class, args);
    }

    @StreamListener(PromotionCacheProcessor.SYNC_CACHE)
    public void syncPromotionCache(Message<PromotionNoticeVo> message) {
        log.info("接收到Spring Cloud Stream消息: {}", message);
        long t1 = System.currentTimeMillis();
        promotionCacheService.loadCache(message.getPayload().getPromotionType());
        long t2 = System.currentTimeMillis();
        log.info("处理消息结束, 耗时: {}ms", t2 - t1);
    }

    @StreamListener(PromotionCacheProcessor.SYNC_RECEIVED)
    public void syncPromotionReceived(Message<PromotionNoticeVo> message) {
        log.info("接收到Spring Cloud Stream消息: {}", message);
        long t1 = System.currentTimeMillis();
        promotionCacheService.loadCache(message.getPayload().getPromotionType());
        long t2 = System.currentTimeMillis();
        log.info("处理消息结束, 耗时: {}ms", t2 - t1);
    }
}

发布了10 篇原创文章 · 获赞 3 · 访问量 171

猜你喜欢

转载自blog.csdn.net/qq_40016813/article/details/103182179
今日推荐