java.lang.IllegalStateException: Failed to load ApplicationContext
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jpaAuditingHandler': Cannot resolve reference to bean 'jpaMappingContext' while setting constructor argument; nested exception is 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!
Caused by: 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!
Caused by: java.lang.IllegalArgumentException: At least one JPA metamodel must be present!
如有任何帮助,不胜感激
这是我的pom:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.2.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>io.rosesnconcrete.services</groupId>
<artifactId>sixersfacts</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>sixersfacts</name>
<description>restful service for sixers facts</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<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>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
下面是我的app.properties:
spring.data.url = jdbc:mysql://localhost:3306/sixersfacts_app?useSSL=false
spring.datasource.username = root
spring.datasource.password = root
spring.datasource.testWhileIdle = true
spring.datasource.validationQuery = SELECT 1
spring.jpa.show-sql = true
spring.jpa.properties.hibernate.dialect =
org.hibernate.dialect.MYSQL5Dialect
spring.jpa.hibernate.ddl-auto = update
spring.autoconfigure.exclude =
org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration
package io.rosesnconcrete.services.model;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import javax.persistence.*;
import javax.validation.constraints.NotBlank;
import java.io.Serializable;
import java.util.Date;
@Entity
@Table(name = "facts")
@EntityListeners(AuditingEntityListener.class)
@JsonIgnoreProperties(value = {"createdAt", "updatedAt"}, allowGetters =
true)
public class SixersFact implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@NotBlank
private String title;
@NotBlank
private String content;
@Column(nullable = false, updatable = false)
@Temporal(TemporalType.TIMESTAMP)
@CreatedDate
private Date createdAt;
@Column(nullable = false)
@Temporal(TemporalType.TIMESTAMP)
@LastModifiedDate
private Date updatedAt;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public Date getCreatedAt() {
return createdAt;
}
public void setCreatedAt(Date createdAt) {
this.createdAt = createdAt;
}
public Date getUpdatedAt() {
return updatedAt;
}
public void setUpdatedAt(Date updatedAt) {
this.updatedAt = updatedAt;
}
@Override
public String toString() {
return "SixersFact{" +
"id=" + id +
", title='" + title + '\'' +
", content='" + content + '\'' +
", createdAt=" + createdAt +
", updatedAt=" + updatedAt +
'}';
}
package io.rosesnconcrete.services.repository;
import io.rosesnconcrete.services.model.SixersFact;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
@Repository
public interface SixersFactRepository extends
JpaRepository<SixersFact,Long> {
}
package io.rosesnconcrete.services.sixersfacts;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
@SpringBootApplication
@EnableJpaAuditing
public class SixersfactsApplication {
public static void main(String[] args) {
SpringApplication.run(SixersfactsApplication.class, args);
}
@springbootapplication
只扫描当前(和子)包(see1),因此io.rosesnconcrete.services.model
、io.rosesnconcrete.services.repository
都被(spring的)“component scan”接收。如果类路径上有spring-boot-starter-data-jpa
,并且没有@entity
IES(在spring上下文中),则会导致此错误消息。(见2)
快速&“按设计”解决方案:
将SixersFactsApplication
移动到io.RosesnConcrete.Services
包(..甚至更高)。
我是springboot的新手,我正在尝试解决以下运行时错误: 如有任何帮助,我将不胜感激 这是我的POM:
在测试我的Controller类时,我遇到了这个异常 我的控制器测试类如下所示 我的引导类 我的依赖项如下所示 IllegalArgumentException:必须至少存在一个JPA元模型没有解决我的问题
问题内容: 在开始使用spring rest时,我得到了如下错误 用下面的代码 以下是我的pom.xml UTF-8 UTF-8 1.8 请帮我。我不知道如何解决这个错误 问题答案: 你已添加 在你的pom.xml中。 Spring Boot会尝试自动为JPA创建实体工厂,但是你尚未定义有关JPA模型的任何内容。 尝试将其删除,以测试到目前为止你做了什么。
从spring rest开始时,我得到以下错误: 带有以下代码 UTF-8 UTF-8 1.8 请帮帮我.我不知道如何解决这个错误
我的父母POM是: 我还添加了JPA: 注意:当我降级到2.0.1时,它可以工作。这是2.0.2中的bug吗??
原因:org.springframework.beans.factory.BeanCreationException:创建名为“JPA MappingContext”的bean时出错:调用init方法失败;嵌套异常是java.lang.IllegalArgumentException:必须至少存在一个JPA元模型!