新的 Spring Data JDK8 Jsr310JpaConverters 不能自动工作? [英] New Spring Data JDK8 Jsr310JpaConverters not working automatically?

查看:41
本文介绍了新的 Spring Data JDK8 Jsr310JpaConverters 不能自动工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 Spring Data JPA 1.8 新的 jdk 日期转换器.

I'm trying to use Spring Data JPA 1.8 new jdk date converters.

在我的 Spring Boot 应用程序中,我添加了一个配置类,如:

In my Spring Boot application I've added a config class like:

@Configuration
@ComponentScan(basePackageClasses = LocalContainerEntityManagerFactoryBean.class)
@EnableJpaAuditing
public class DataConfig {
}

这是org.springframework.data.jpa.convert.threeten.Jsr310JpaConverters 建议如何应用自动转换的方式.我还使用了直接包引用,如 org.springframework.data.jpa.domain.supportorg.springframework.data.jpa.convert.threeten.

This is how org.springframework.data.jpa.convert.threeten.Jsr310JpaConverters suggests how to apply the auto conversion. I also used direct package references like org.springframework.data.jpa.domain.support and org.springframework.data.jpa.convert.threeten.

问题是jdk 8日期转换没有发生导致sql异常.

The problem is the jdk 8 date conversion do not happen resulting in sql exceptions.

但是,当我手动将转换器应用到我的域类中时:

However, when I apply the converter manually to in my domain class like:

@Convert(converter = Jsr310JpaConverters.LocalDateConverter.class)
private LocalDate birthdate;

然后转换确实有效.

推荐答案

使用 Spring Boot 只需添加如下 Jsr310JpaConverters

Using Spring Boot can simply add Jsr310JpaConverters like below

@EntityScan(basePackageClasses = { Application.class, Jsr310JpaConverters.class })
@SpringBootApplication
class Application { … }

或者在要扫描的包中添加org.springframework.data.jpa.convert.threeten.

or add org.springframework.data.jpa.convert.threeten to the packages to scan.

这篇关于新的 Spring Data JDK8 Jsr310JpaConverters 不能自动工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆