在下面,我将创建EntityManagerfactory对象和EntityManager对象
@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);
}
以下是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'
}
}
下面是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
当我在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
以下日志的其他部分
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
我已经在网上搜索并应用了这些解决方案,但没有工作,请建议任何可能的解决方案,这个问题与 Spring Boot 3. 0
1条答案
按热度按时间nbysray51#
以下是可能导致
entityManagerFactory
问题的问题。下面是www.example.com文件gradle.properties file
Spring boot 3.0.x
支持雅加达EE 9和雅加达EE 10。因此,您至少需要使用hib
5.5.0.Final
版本,但最好迁移到hib6.x
版本。原因是Spring boot 3.0
符合基于Jakarta Persistence 3.0的Jakarta EE 9,并且这是第一次在hib5.5.0.Final
中实现。Spring boot 3.0
还符合基于Jakarta Persistence 3.1的Jakarta EE 10,这首先在hib6.0
版本中实现。目前的spring boot版本是
3.0.2
,所以如果你看一下cli
版本坐标,它也与spring-initializer
用来创建spring boot项目的坐标相同,插入正确的依赖项,你可以看到它为spring boot3.0.2
使用了hibernate-core
版本6.1.6.Final
。