栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

Spring-boot + JPA EntityManager注入失败

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Spring-boot + JPA EntityManager注入失败

您应该将依赖项用于spring-boot-starter-data-jpa

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

要使用持久性xml,您应该按照文档中的定义定义一个bean。

Spring不需要使用XML来配置JPA提供程序,并且Spring
Boot假定您想利用该功能。如果您更喜欢使用persistence.xml,则需要定义自己的@Bean,其类型为LocalEntityManagerFactoryBean(标识为’entityManagerFactory’,并在其中设置持久性单元名称)。

http://docs.spring.io/spring-boot/docs/current/reference/html/howto-data-
access.html#howto-use-traditional-persistence-
xml

或者,您可以完全跳过persistence.xml,并在application.properties文件中定义连接属性。

引用文档

DataSource配置由spring.datasource。*中的外部配置属性控制。例如,您可以在application.properties中声明以下部分:

spring.datasource.url=jdbc:mysql://localhost/testspring.datasource.username=dbuserspring.datasource.password=dbpassspring.datasource.driver-class-name=com.mysql.jdbc.Driver

http://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-
sql.html#boot-features-connect-to-production-
database

(更改驱动程序和其他数据以匹配您的环境)

祝好运!



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/670701.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号