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);
    }
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章