我正在将应用程序从Spring Boot 1.5迁移到2(并希望从Tomcat迁移到Hikari)。我已经解决了所有编译错误,但是现在我遇到了这个错误(我删除了大多数stacktrace,因为我看不到任何重要信息):

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'pexEntityManagerFactory' defined in class path resource [com/xisumavoid/gateway/db/PexDbConfig.class]: Invocation of init method failed; nested exception is org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
[...]
Caused by: org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set


我有2个类充当数据库配置,因为我的应用程序必须访问2个数据库(名为“ primary”和“ pex”)。 PexDbConfig看起来像这样:

@Configuration
@EnableTransactionManagement
@EnableJpaRepositories(
    entityManagerFactoryRef = "pexEntityManagerFactory",
    transactionManagerRef = "pexTransactionManager",
    basePackages = { "com.xisumavoid.gateway.db.pex.repositories" }
)
public class PexDbConfig {

    @Bean(name = "pexDataSource")
    @ConfigurationProperties(prefix = "pex.datasource")
    public DataSource dataSource() {
        return DataSourceBuilder.create().build();
    }

    @Bean(name = "pexEntityManagerFactory")
    public LocalContainerEntityManagerFactoryBean pexEntityManagerFactory(
        EntityManagerFactoryBuilder builder,
        @Qualifier("pexDataSource") DataSource dataSource
    ) {
        return builder
                .dataSource(dataSource)
                .packages("com.xisumavoid.gateway.db.pex.models")
                .persistenceUnit("pex")
                .build();
    }

    @Bean(name = "pexTransactionManager")
    public PlatformTransactionManager pexTransactionManager(
            @Qualifier("pexEntityManagerFactory") EntityManagerFactory
                    pexEntityManagerFactory
    ) {
        return new JpaTransactionManager(pexEntityManagerFactory);
    }
}


抱歉,代码混乱,长类名很难处理。
另外,如果需要的话,以下是相关的配置部分:

## DB - PRIMARY
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/primary
spring.datasource.username=user
spring.datasource.password=password

## DB - PEX
pex.datasource.driver-class-name=com.mysql.jdbc.Driver
pex.datasource.url=jdbc:mysql://localhost:3306/pex
pex.datasource.username=user
pex.datasource.password=password


我该如何解决这个问题,或者甚至更好,有没有办法以更简单的方式做到这一点?

提前致谢!

最佳答案

按照this thread,添加

spring.jpa.database-platform=org.hibernate.dialect.MySQL57Dialect


我的application.properties做到了。

10-05 18:25