当前位置: 首页 > 知识库问答 >
问题:

创建名为“jpa mappingcontext”的bean时出错:调用init方法失败;:必须至少存在一个JPA元模型

谷博艺
2023-03-14
<dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
            <version>1.5.6.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <version>1.5.6.RELEASE</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-data-jpa -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
            <version>2.0.3.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>8.0.11</version>
        </dependency>
    </dependencies>
@RestController
public class EmployeeController {

    @Autowired
    EmployeeInterface empInterface;

    @RequestMapping("/getAll")
    public List<Employee> getEmployees() {
        return (List<Employee>)empInterface.findAll();
    }
}
@Entity
@Table(name="Employee")
public class Employee implements Serializable {

    private static final long serialVersionUID = 5406213393320888178L;

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name="id")
    private Long id;
    @Column(name="fname")
    private String fname;
    @Column(name="lname")
    private String lname;

原因:org.springframework.beans.factory.BeanCreationException:创建名为“JPA MappingContext”的bean时出错:调用init方法失败;嵌套异常是java.lang.IllegalArgumentException:必须至少存在一个JPA元模型!

共有1个答案

苏浩瀚
2023-03-14

使用此依赖关系:

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

您使用spring boot版本1.5.6,但给出了spring boot 2.0.3的jpa依赖项

更改mysql连接器版本:

<dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>5.1.46</version>
    </dependency>
 类似资料: