非法符号评估:必须至少有一个JPA元模型



从春季休息开始时,我得到了以下错误,

>  org.springframework.beans.factory.BeanCreationException: Error
> creating bean with name 'jpaMappingContext': Invocation of init method
> failed; nested exception is java.lang.IllegalArgumentException: At
> least one JPA metamodel must be present!
>       at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1595)
> ~[spring-beans-5.0.0.BUILD-SNAPSHOT.jar:5.0.0.BUILD-SNAPSHOT]
>       at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:566)
> ~[spring-beans-5.0.0.BUILD-SNAPSHOT.jar:5.0.0.BUILD-SNAPSHOT]
>       at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
> ~[spring-beans-5.0.0.BUILD-SNAPSHOT.jar:5.0.0.BUILD-SNAPSHOT]
>       at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304)
> ~[spring-beans-5.0.0.BUILD-SNAPSHOT.jar:5.0.0.BUILD-SNAPSHOT]
>       at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
> ~[spring-beans-5.0.0.BUILD-SNAPSHOT.jar:5.0.0.BUILD-SNAPSHOT]
>       at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300)
> ~[spring-beans-5.0.0.BUILD-SNAPSHOT.jar:5.0.0.BUILD-SNAPSHOT]
>       at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195)
> ~[spring-beans-5.0.0.BUILD-SNAPSHOT.jar:5.0.0.BUILD-SNAPSHOT]
>       at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:725)
> ~[spring-beans-5.0.0.BUILD-SNAPSHOT.jar:5.0.0.BUILD-SNAPSHOT]
>       at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:866)
> ~[spring-context-5.0.0.BUILD-SNAPSHOT.jar:5.0.0.BUILD-SNAPSHOT]
>       at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:542)
> ~[spring-context-5.0.0.BUILD-SNAPSHOT.jar:5.0.0.BUILD-SNAPSHOT]
>       at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122)
> ~[spring-boot-2.0.0.BUILD-SNAPSHOT.jar:2.0.0.BUILD-SNAPSHOT]
>       at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:736)
> [spring-boot-2.0.0.BUILD-SNAPSHOT.jar:2.0.0.BUILD-SNAPSHOT]
>       at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:369)
> [spring-boot-2.0.0.BUILD-SNAPSHOT.jar:2.0.0.BUILD-SNAPSHOT]
>       at org.springframework.boot.SpringApplication.run(SpringApplication.java:313)
> [spring-boot-2.0.0.BUILD-SNAPSHOT.jar:2.0.0.BUILD-SNAPSHOT]
>       at org.springframework.boot.SpringApplication.run(SpringApplication.java:1161)
> [spring-boot-2.0.0.BUILD-SNAPSHOT.jar:2.0.0.BUILD-SNAPSHOT]
>       at org.springframework.boot.SpringApplication.run(SpringApplication.java:1150)
> [spring-boot-2.0.0.BUILD-SNAPSHOT.jar:2.0.0.BUILD-SNAPSHOT]
>       at com.java.app.QuickPollApplication.main(QuickPollApplication.java:14)
> [classes/:na]
>     Caused by: java.lang.IllegalArgumentException: At least one JPA metamodel must be present!
>       at org.springframework.util.Assert.notEmpty(Assert.java:438) ~[spring-core-5.0.0.BUILD-SNAPSHOT.jar:5.0.0.BUILD-SNAPSHOT]
>       at org.springframework.data.jpa.mapping.JpaMetamodelMappingContext.<init>(JpaMetamodelMappingContext.java:52)
> ~[spring-data-jpa-1.11.0.BUILD-SNAPSHOT.jar:na]
>       at org.springframework.data.jpa.repository.config.JpaMetamodelMappingContextFactoryBean.createInstance(JpaMetamodelMappingContextFactoryBean.java:71)
> ~[spring-data-jpa-1.11.0.BUILD-SNAPSHOT.jar:na]
>       at org.springframework.data.jpa.repository.config.JpaMetamodelMappingContextFactoryBean.createInstance(JpaMetamodelMappingContextFactoryBean.java:26)
> ~[spring-data-jpa-1.11.0.BUILD-SNAPSHOT.jar:na]
>       at org.springframework.beans.factory.config.AbstractFactoryBean.afterPropertiesSet(AbstractFactoryBean.java:134)
> ~[spring-beans-5.0.0.BUILD-SNAPSHOT.jar:5.0.0.BUILD-SNAPSHOT]
>       at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1654)
> ~[spring-beans-5.0.0.BUILD-SNAPSHOT.jar:5.0.0.BUILD-SNAPSHOT]
>       at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1591)
> ~[spring-beans-5.0.0.BUILD-SNAPSHOT.jar:5.0.0.BUILD-SNAPSHOT]
>       ... 16 common frames omitted

以下代码

@SpringBootApplication
@RestController
public class QuickPollApplication {
    public static void main(String[] args) {
        SpringApplication.run(QuickPollApplication.class, args);
    }
    @RequestMapping(value = "/test", method = RequestMethod.GET)
    public String testRest() {
        return "rest tested";
    }

和以下是我的pom.xml

UTF-8 UTF-8 1.8 org.springframework.boot Spring-Boot-Starter-Data-JPA org.springframework.boot 弹簧启动启动 org.springframework.boot 弹簧启动启动 - 网络服务 org.hsqldb HSQLDB 运行 org.springframework.boot 弹簧启动测试 测试 org.springframework 春季 org.springframework.boot 弹簧启动 - 刺激性 弹簧刺 春季快照 https://repo.spring.io/snapshot 真的 春季米勒斯坦 春季里程碑 https://repo.spring.io/milestone 错误的 弹簧刺 春季快照 https://repo.spring.io/snapshot 真的 春季米勒斯坦 春季里程碑 https://repo.spring.io/milestone 错误的

请帮助我。我不知道如何解决此错误

您添加了

<dependency>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>

在您的pom.xml中。

Spring Boot将尝试自动为JPA创建实体工厂,但是您尚未定义有关JPA型号的任何内容。

尝试将其删除以测试您到目前为止所做的事情。

之后,您可以使用Spring-Data-starter-jpa检查教程,例如这个人

我已经通过设置较新版本的Hibernate修复了它。

<dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
         <exclusions>
             <exclusion>
                <groupId>org.hibernate</groupId>
                <artifactId>hibernate-entitymanager</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.hibernate</groupId>
                <artifactId>hibernate-core</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
        <version>5.2.10.Final</version>
    </dependency>

您可以在此处找到一个完全有效的示例:https://github.com/zobarov/ptc-task-executor

您还可以通过排除以下自动配置类(例如在@EnableAutoConfiguration@SpringBootApplication注释中)来禁用Spring Data JPA的存储库支持

org.springframework.boot.autoconfigure.data.jpa.JpaRepositoriesAutoConfiguration

例如:

@EnableAutoConfiguration(exclude = JpaRepositoriesAutoConfiguration.class)

这对我有用。

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-jpa</artifactId>
     <exclusions>
         <exclusion>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-entitymanager</artifactId>
        </exclusion>
        <exclusion>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
        </exclusion>
    </exclusions>
</dependency>
<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-core</artifactId>
    <version>5.2.10.Final</version>
</dependency>

相关内容

  • 没有找到相关文章

最新更新