簡體   English   中英

從Spring Boot 1.5遷移到2,多個數據源上的錯誤

[英]Migrating from Spring Boot 1.5 to 2, error on multiple data sources

我正在將應用程序從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

我該如何解決這個問題,或者甚至更好,有沒有辦法以更簡單的方式做到這一點?

提前致謝!

按照此線程 ,添加

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

我的application.properties達到目的。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM