简体   繁体   English

我正在将 spring 引导版本 2.7.3 迁移到 spring-boot 3.0.0,因此现有代码正在中断相关的 EntityManagerfactory 无法正常工作

[英]I am migrating spring boot version 2.7.3 to spring-boot 3.0.0 so existing code is breaking related EntityManagerfactory is not working

In below I am creating EntityManagerfactory object and EntityManager object在下面我正在创建 EntityManagerfactory object 和 EntityManager object

    @Override
    public boolean isTenantSchemaExist(String tenantId) {
        EntityManagerFactory factory = 
            Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME);
        EntityManager manager = factory.createEntityManager();
        Query getSchemasQuery = manager.createNativeQuery(TENANT_SCHEMA_EXIST_QUERY);
        List<String> tenantSchemas = new ArrayList(getSchemasQuery.getResultList());
        return tenantSchemas.contains(tenantId);
    }

Below is build.gradle file content下面是build.gradle文件内容

dependencies {
    implementation "org.apache.logging.log4j:log4j-core:2.17.1"
    implementation "org.apache.logging.log4j:log4j-api:2.17.1"
    implementation "org.apache.logging.log4j:log4j-1.2-api:2.17.1"
    implementation 'org.apache.logging.log4j:log4j-to-slf4j:2.17.1'
    implementation "com.nexidia:nexidia-semanticanalysis:${semanticanalysisVersion}"
    implementation(group: 'com.nexidia', name: 'nexidia-workbench', version: '10.6.2.13',                 
    implementation ('org.springframework.boot:spring-boot-starter-web'){
    exclude group : 'org.yaml' , module : 'snakeyaml'
    }
    implementation 'org.springframework.retry:spring-retry'
    implementation ("org.springframework.boot:spring-boot-starter-data-jpa"){
    exclude group : 'org.yaml' , module : 'snakeyaml'
    exclude group: 'org.hibernate.orm', module: 'hibernate-core'
    }
    implementation 'org.springframework:spring-aspects'
    implementation ("com.attensity:lib-auto-discovery-dao:${libDaoVersion}"){
    exclude group : 'org.yaml' , module : 'snakeyaml'
    }
    
    implementation "com.amazonaws:aws-java-sdk-dynamodb:${awsSDKVersion}"
    implementation ("com.amazonaws:aws-java-sdk-core:${awsSDKVersion}"){
    exclude group : 'org.yaml' , module : 'snakeyaml'
    }
    implementation "com.amazonaws:aws-java-sdk-ssm:${awsSDKVersion}"
    implementation "com.nice.cea.cat:lib-feature-flags:${featureFlagsLibVersion}"
    implementation "com.google.guava:guava:${guavaVersion}"
    implementation "org.flywaydb:flyway-core:${flywayVersion}"
    implementation group: 'commons-io', name: 'commons-io', version: '2.7'
    //  For assuming role in local dev mode
    implementation "com.amazonaws:aws-java-sdk-sts:${awsSDKVersion}"
    implementation "org.postgresql:postgresql:${postgresJdbcVersion}"
    /*implementation ("org.hibernate:hibernate-c3p0:${hibernateVersion}"){
    exclude group : 'javax.persistence' , module : 'javax.persistence-api'
    }*/
    implementation "org.apache.httpcomponents.client5:httpclient5:${httpclient5}"
    implementation 'jakarta.persistence:jakarta.persistence-api'
    testImplementation "cloud.localstack:localstack-utils:${localStackUtilsVersion}"
    testImplementation ("com.attensity:lib-auto-discovery-dao-test:${libDaoTestVersion}"){
    exclude group : 'org.yaml' , module : 'snakeyaml'
    }
    testImplementation "org.testcontainers:postgresql:${testPostgresVersion}"
    testImplementation "junit:junit:${junitVersion}"
    testImplementation 'jakarta.persistence:jakarta.persistence-api'
    testImplementation('org.springframework.boot:spring-boot-starter-test') {
    exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
    exclude group : 'org.yaml' , module : 'snakeyaml'
    }
    }

Below is gradle.properties file下面是 gradle.properties 文件

    semanticanalysisVersion=10.6.2.13
    workbenchVersion=10.6.2.13
    junitVersion=4.13.1
    libDaoVersion=SpringBoot_Test2-SNAPSHOT
    libDaoTestVersion=1.0.7
    libPhraseFilterVersion=1.0.3
    awsSDKVersion=1.11+
    testPostgresVersion=1.15.0
    jacocoVersion=0.8.7
    localStackUtilsVersion=0.1.22
    guavaVersion=31.1-jre
    servicePort=80
    version=22.1.0
    serviceName=auto-discovery-model-generator
    featureFlagsLibVersion=1.0.0-RELEASE
    postgresJdbcVersion=42.4.1
    hibernateVersion=5.4.26.Final
    secretsManagerJdbcVersion=1.0.5
    secretsManagerCacheVersion=1.0.1
    flywayVersion=6.4.3
    httpclient5=5.2
    httpclient5Fluent=5.2

while I am getting below error on Jenkins build当我在 Jenkins 构建时遇到错误

15:13:59      2023-01-31T09:43:59.527Z  INFO 1626 --- \[    Test worker\]                                             com.zaxxer.hikari.HikariDataSource       : HikariPool-2 - Start completed 
15:13:59      2023-01-31T09:43:59.528Z  WARN 1626 --- \[    Test worker\]           o.s.w.c.s.GenericWebApplicationContext   : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource \[org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class\]: Class org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider does not implement the requested interface jakarta.persistence.spi.PersistenceProvider
15:13:59      2023-01-31T09:43:59.529Z  INFO 1626 --- \[    Test worker\] com.zaxxer.hikari.HikariDataSource       : HikariPool-2 - Shutdown initiated...
15:13:59      2023-01-31T09:43:59.529Z  INFO 1626 --- \[    Test worker\] com.zaxxer.hikari.HikariDataSource       : HikariPool-2 - Shutdown completed.
15:13:59      2023-01-31T09:43:59.533Z  INFO 1626 --- \[    Test worker\] .s.b.a.l.ConditionEvaluationReportLogger :
15:13:59  
15:13:59      Error starting ApplicationContext. To display the condition evaluation report re-run your application with 'debug' enabled.
15:13:59      2023-01-31T09:43:59.534Z ERROR 1626 --- \[    Test worker\] o.s.boot.SpringApplication               : Application run failed

Other portion of log below下面日志的其他部分

15:14:04      2023-01-31T09:44:04.890Z  WARN 1626 --- \[    Test worker\] o.s.w.c.s.GenericWebApplicationContext   : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jpaSharedEM_entityManagerFactory': Cannot resolve reference to bean 'entityManagerFactory' while setting constructor argument
15:14:04      2023-01-31T09:44:04.892Z  INFO 1626 --- \[    Test worker\] .s.b.a.l.ConditionEvaluationReportLogger :
15:14:04  
15:14:04      Error starting ApplicationContext. To display the condition evaluation report re-run your application with 'debug' enabled.
15:14:04      2023-01-31T09:44:04.894Z ERROR 1626 --- \[    Test worker\] o.s.b.d.LoggingFailureAnalysisReporter   :
15:14:04  
15:14:04      \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
15:14:04      APPLICATION FAILED TO START
15:14:04      \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
15:14:04  
15:14:04      Description:
15:14:04  
15:14:04      A component required a bean named 'entityManagerFactory' that could not be found.
15:14:04  
15:14:04  
15:14:04      Action:
15:14:04  
15:14:04      Consider defining a bean named 'entityManagerFactory' in your configuration.
15:14:04  
15:14:04  
15:14:04  com.attensity.modelgenerator.unit.ModelGeneratorServiceWorkbenchTest STANDARD_ERROR
15:14:04  
15:14:04

I have searched on.net and applied those solutions but did not work out Please suggest any possible solution for this problem with spring boot 3.0我已经在网上搜索并应用了这些解决方案,但没有成功 请为 spring boot 3.0 提出任何可能的解决方案

Here is your problem that probably causes the entityManagerFactory issue.这是可能导致entityManagerFactory问题的问题。

Below is gradle.properties file下面是 gradle.properties 文件

hibernateVersion=5.4.26.Final

Spring boot 3.0.x supports Jakarta EE 9 and Jakarta EE 10 . Spring boot 3.0.x支持Jakarta EE 9Jakarta EE 10

So you need to use at least hibernate 5.5.0.Final version but better to migrate to hibernate 6.x version.所以你需要至少使用 hibernate 5.5.0.Final版本,但最好迁移到 hibernate 6.x版本。 Reason is that Spring boot 3.0 complies with Jakarta EE 9 which is based on Jakarta Persistence 3.0 and this was first implemented into hibernate 5.5.0.Final .原因是Spring boot 3.0符合基于Jakarta Persistence 3.0Jakarta EE 9 ,这首先在 hibernate 5.5.0.Final中实现。

Spring boot 3.0 also complies with Jakarta EE 10 which is based on Jakarta Persistence 3.1 and this was first implemented into hibernate 6.0 version. Spring boot 3.0还符合基于Jakarta Persistence 3.1Jakarta EE 10 ,这首先在 hibernate 6.0版本中实现。

The current version of spring boot at the time speaking is 3.0.2 and so if you take a look on the cli version coordinates which is also the same as what spring-initializer uses to create a spring boot project plugging in the right dependencies you can see that it uses for spring boot 3.0.2 the hibernate-core version 6.1.6.Final .目前 spring 引导的当前版本是3.0.2 ,因此如果您查看cli 版本坐标,它也与spring-initializer用于创建插入正确依赖项的 spring 引导项目相同,您可以看到它用于 spring 引导3.0.2 hibernate-core版本6.1.6.Final

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Spring-boot测试中的EntityManagerFactory Bean - EntityManagerFactory Bean in Spring-boot test Spring Boot 版本 3.0.0 不适用于 jaeger 3.3.1(最新版本) - Spring boot version 3.0.0 is not working with jaeger 3.3.1 (latest version) 将现有的Spring应用程序转换为Spring-Boot - Convert existing Spring application to Spring-Boot Spring-boot ReloadableResourceBundleMessageSource 不工作 - Spring-boot ReloadableResourceBundleMessageSource not working Spring-boot:需要一个无法找到的名为“entityManagerFactory”的 bean - Spring-boot: required a bean named 'entityManagerFactory' that could not be found [Spring-Boot] Controller需要一个名为&#39;entityManagerFactory&#39;的文件,找不到 - [Spring-Boot]Controller required a been named 'entityManagerFactory' that could not be found 调试在 STS(Spring Tool Suite)中的 Spring Boot 2.7.3 应用程序上不起作用 - Debug not working on Spring Boot 2.7.3 application in STS (Spring Tool Suite) Springfox 3.0.0 不适用于 Spring Boot 2.6.0 - Springfox 3.0.0 is not working with Spring Boot 2.6.0 安全地覆盖 spring-boot 依赖版本 - safely overriding spring-boot dependency version 将 Sleuth 迁移到观察 API by Micrometar Spring Boot 3.0.0 - Migrating Sleuth to Observation API by Micrometar Spring Boot 3.0.0
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM