Spring Boot 应用程序中的 JPA
开发者可以使用 Java™ 持久性 API (JPA) 来创建面向对象的关系数据库实体版本,以在其应用程序中使用。
要在 Spring Boot 应用程序中使用 JPA ,请首先将 JPA 工件添加到 Spring Boot 应用程序中的依赖项。 例如:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>Java EE的 JPA 实现和 Spring 数据的 JPA 实现都需要配置以定义与应用程序所使用的数据库存储库的连接。
就像使用 JDBC 一样,您可以使用 application.properties 中定义的 spring.datasource.jndi-name 属性来配置与正在使用的数据源的连接,这将由 JPA EntityManager动态使用。 或者,也可以通过在Liberty中定义的数据源的JNDI查找,在带有@Bean注释的 dataSource( 方法中定义数据源。