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

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

问题描述

我正在尝试使用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 Jsr310Jpa转换器不能自动工作吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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