为了账号安全,请及时绑定邮箱和手机立即绑定

创建在类路径资源中定义的名称为'entityManagerFactory'的bean时出错:

创建在类路径资源中定义的名称为'entityManagerFactory'的bean时出错:

慕勒3428872 2019-10-17 15:32:14
编译spring项目时,出现以下错误。创建在类路径资源[org / springframework / boot / autoconfigure / orm / jpa / HibernateJpaAutoConfiguration.class]中定义的名称为'entityManagerFactory'的bean时出错:调用init方法失败我正在使用STS Eclipse和MySql数据库我的连接字符串Application.Properties是spring.datasource.url=jdbc:mysql://localhost:3306/stgdbspring.datasource.username=rootspring.datasource.password=rootspring.datasource.driver-class-name=com.mysql.jdbc.Driverspring.jpa.hibernate.ddl-auto=update详细错误如下=================================================2016-10-15 15:34:38.875[0;39m [31mERROR[0;39m [35m3700[0;39m [2m---[0;39m [2m[           main][0;39m [36mo.s.boot.SpringApplication              [0;39m [2m:[0;39m Application startup failedorg.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1583) ~[spring-beans-4.3.3.RELEASE.jar:4.3.3.RELEASE]    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:545) ~[spring-beans-4.3.3.RELEASE.jar:4.3.3.RELEASE]    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) ~[spring-beans-4.3.3.RELEASE.jar:4.3.3.RELEASE]    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-
查看完整描述

3 回答

?
函数式编程

TA贡献1807条经验 获得超9个赞

我将从添加以下依赖关系开始:


<dependency>

    <groupId>org.hibernate</groupId>

    <artifactId>hibernate-core</artifactId>

    <version>4.1.4.Final</version>

</dependency>


<dependency>

    <groupId>org.hibernate</groupId>

    <artifactId>hibernate-entitymanager</artifactId>

    <version>5.2.3.Final</version>

</dependency>

更新 :或只需添加以下依赖项。


<dependency>

        <groupId>javax.xml.bind</groupId>

        <artifactId>jaxb-api</artifactId>

        <version>2.3.0</version>

</dependency>


查看完整回答
反对 回复 2019-10-17
?
慕盖茨4494581

TA贡献1850条经验 获得超11个赞

使用Java 9的人包括这种依赖关系:


<dependency>

        <groupId>javax.xml.bind</groupId>

        <artifactId>jaxb-api</artifactId>

        <version>2.3.0</version>

</dependency>


查看完整回答
反对 回复 2019-10-17
?
慕姐8265434

TA贡献1813条经验 获得超2个赞

我也面临同样的问题。我正在使用Java9,并在pom文件中遵循以下依赖关系:


<dependencies>

    <dependency>

        <groupId>org.springframework.boot</groupId>

        <artifactId>spring-boot-starter-data-jpa</artifactId>

    </dependency>

    <dependency>

        <groupId>org.springframework.boot</groupId>

        <artifactId>spring-boot-starter-jdbc</artifactId>

    </dependency>

    <dependency>

        <groupId>org.springframework.boot</groupId>

        <artifactId>spring-boot-starter-web</artifactId>

    </dependency>

    <dependency>

        <groupId>com.h2database</groupId>

        <artifactId>h2</artifactId>

        <scope>runtime</scope>

    </dependency>

    <dependency>

        <groupId>org.springframework.boot</groupId>

        <artifactId>spring-boot-starter-test</artifactId>

        <scope>test</scope>

    </dependency>

</dependencies>

在pom中添加以下依赖项后,此问题已解决:


    <dependency>

        <groupId>javax.xml.bind</groupId>

        <artifactId>jaxb-api</artifactId>

        <version>2.3.0</version>

    </dependency>


查看完整回答
反对 回复 2019-10-17
  • 3 回答
  • 0 关注
  • 1292 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信