小编ezt*_*ams的帖子

Spring Boot 2.0.0.M4 & Hibernate 5.2.11.Final 找不到 EntityManagerFactoryBuilder 类型的 bean

我显然有一些配置问题,但我自己无法解决这个问题。我希望你们能帮帮我?

我发现的所有示例都没有表明必须为 EntityManagerFactoryBuilder 创建一个 bean,所以有什么问题。

我正在尝试配置完全独立的数据源,包括不同的实体管理器等。

我的错误:


应用程序无法启动


描述:

方法 entityManagerFactory 的参数 0 需要一个无法找到的“org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder”类型的 bean。

行动:

考虑在您的配置中定义一个 'org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder' 类型的 bean。

我的数据源配置

package ...;

import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import javax.sql.DataSource;

@Configuration
@EnableTransactionManagement
public class DataSourceConfiguration {


    @Primary
    @Bean()
    @ConfigurationProperties(prefix="spring.my.datasource")
    public DataSource myDataSource() {
        return DataSourceBuilder.create().build();
    }



    @Primary
    @Bean(name = "myEntityManager")
    public LocalContainerEntityManagerFactoryBean entityManagerFactory(EntityManagerFactoryBuilder factoryBuilder,
                                                                       @Qualifier("myEntityManager") DataSource bds) {
        ...
    }
}
Run Code Online (Sandbox Code Playgroud)

我的应用程序

@SpringBootApplication(exclude = {
        DataSourceAutoConfiguration.class,
        HibernateJpaAutoConfiguration.class, …
Run Code Online (Sandbox Code Playgroud)

spring-boot hibernate-5.x

5
推荐指数
2
解决办法
1万
查看次数

DateTimeFormatter.ISO_OFFSET_DATE_TIME 未按预期工作

基于此 Java 日期时间 - OffsetDateTime.format() 示例文章和DateTimeFormatter 的官方文档,我希望我的 OffsetDateTime 被序列化为自 UTC 以来2011-12-03T10:15:30+00:00偏移量的偏移量+00:00

我无法让 OffsetDateTime 使用偏移量进行渲染,它总是只使用“Z”祖鲁语进行渲染。我究竟做错了什么?

在此处输入图片说明

这是Spring Boot 2.0.0.RELEASE,正如您在屏幕截图中看到的,我在类路径上有以下模块并注册了 objectMapper,尽管我认为这不是相对的,因为这个问题似乎是直接的使用 DateTimeFormatter,我的对象映射器只是使用我提供的格式化程序。

它确实有影响,因为正如您在第二个屏幕截图中看到的那样,当我指定BASIC_ISO_FORMAT它确实会产生不同的结果。

我确实spring.jackson.date-format= com.fasterxml.jackson.databind.util.ISO8601DateFormat在我的 application.properties 中设置了这个属性,但据我所知,这对 OffsetDateTime 没有影响,它只支持旧版 java 中的遗留 Date 对象。顺便说一下,改变这一点似乎没有预期的影响。

任何帮助,将不胜感激。

使用 ISO_ZONED_DATE_TIME 格式... 使用 ISO_ZONED_DATE_TIME 格式

使用 BASIC_ISO_FORMAT ... 这确实有影响,所以我知道格式化程序正在做某事,我只是不清楚为什么 ISO_ZONED_DATE_TIME 没有按预期呈现。 使用 BASIC_ISO_FORMAT

 this.objectMapper = objectMapperBuilder.build()      
      .setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE)
      .disable(SerializationFeature.INDENT_OUTPUT)
      .disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
      .disable(SerializationFeature.WRITE_DATES_WITH_ZONE_ID);

 SimpleModule simpleModule = new SimpleModule();
 simpleModule.addSerializer(OffsetDateTime.class, new JsonSerializer<OffsetDateTime>() {
        @Override
        public void serialize(OffsetDateTime offsetDateTime, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException …
Run Code Online (Sandbox Code Playgroud)

datetimeoffset datetime-format spring-boot

3
推荐指数
1
解决办法
7628
查看次数