我正在使用ObjectDB在Spring-Boot中实现一个程序。为了实际使用ObjectDB,我遵循了这种方法https://www.objectdb.com/forum/2523,它工作得很好。
然而,只要我想使用Spring-Actuator,我就会得到以下错误:
Error creating bean with name 'org.springframework.boot.actuate.autoconfigure.metrics.orm.jpa.HibernateMetricsAutoConfiguration': Injection of autowired dependencies failed; nested exception is com.objectdb.o.UserException: Unsupported unwrap(org.hibernate.SessionFactory.class) for EntityManagerFactory 对如何解决这个错误有什么想法吗?
我使用的代码与链接中的代码完全相同。我在pom中添加了Spring-Actuator,如下所示:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>发布于 2021-02-07 00:43:37
失败的发生是因为Spring Boot试图解开JPA EntityManagerFactory以获取Hibernate的SessionFactory。它试图这样做,因为您在类路径上使用Hibernate (它是spring-boot-starter-data-jpa的依赖项)。根据JPA规范,“如果提供者不支持调用”,unwrap应该抛出一个PersistenceException。Spring Boot在不支持unwrap的情况下捕获PersistenceException。不幸的是,ObjectDB抛出了不符合规范的com.objectdb.o.UserException。我建议将其作为ObjectDB错误来提出来。
您可以通过从类路径中排除Hibernate来避免这个问题。这将阻止Spring Boot尝试解开Hibernate的SessionFactory,从而防止ObjectDB错误的发生。可以通过向pom.xml中的spring-boot-starter-data-jpa依赖项添加排除来执行此操作
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<exclusions>
<exclusion>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
</exclusion>
</exclusions>
</dependency>https://stackoverflow.com/questions/66077446
复制相似问题