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

编译spring项目时,出现以下错误。


创建在类路径资源[org / springframework / boot / autoconfigure / orm / jpa / HibernateJpaAutoConfiguration.class]中定义的名称为'entityManagerFactory'的bean时出错:调用init方法失败


我正在使用STS Eclipse和MySql数据库


我的连接字符串Application.Properties是


spring.datasource.url=jdbc:mysql://localhost:3306/stgdb

spring.datasource.username=root

spring.datasource.password=root

spring.datasource.driver-class-name=com.mysql.jdbc.Driver

spring.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 failed


org.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-

慕勒3428872
浏览 1247回答 3
3回答

函数式编程

我将从添加以下依赖关系开始:<dependency>&nbsp; &nbsp; <groupId>org.hibernate</groupId>&nbsp; &nbsp; <artifactId>hibernate-core</artifactId>&nbsp; &nbsp; <version>4.1.4.Final</version></dependency>和<dependency>&nbsp; &nbsp; <groupId>org.hibernate</groupId>&nbsp; &nbsp; <artifactId>hibernate-entitymanager</artifactId>&nbsp; &nbsp; <version>5.2.3.Final</version></dependency>更新 :或只需添加以下依赖项。<dependency>&nbsp; &nbsp; &nbsp; &nbsp; <groupId>javax.xml.bind</groupId>&nbsp; &nbsp; &nbsp; &nbsp; <artifactId>jaxb-api</artifactId>&nbsp; &nbsp; &nbsp; &nbsp; <version>2.3.0</version></dependency>

慕盖茨4494581

使用Java 9的人包括这种依赖关系:<dependency>&nbsp; &nbsp; &nbsp; &nbsp; <groupId>javax.xml.bind</groupId>&nbsp; &nbsp; &nbsp; &nbsp; <artifactId>jaxb-api</artifactId>&nbsp; &nbsp; &nbsp; &nbsp; <version>2.3.0</version></dependency>

慕姐8265434

我也面临同样的问题。我正在使用Java9,并在pom文件中遵循以下依赖关系:<dependencies>&nbsp; &nbsp; <dependency>&nbsp; &nbsp; &nbsp; &nbsp; <groupId>org.springframework.boot</groupId>&nbsp; &nbsp; &nbsp; &nbsp; <artifactId>spring-boot-starter-data-jpa</artifactId>&nbsp; &nbsp; </dependency>&nbsp; &nbsp; <dependency>&nbsp; &nbsp; &nbsp; &nbsp; <groupId>org.springframework.boot</groupId>&nbsp; &nbsp; &nbsp; &nbsp; <artifactId>spring-boot-starter-jdbc</artifactId>&nbsp; &nbsp; </dependency>&nbsp; &nbsp; <dependency>&nbsp; &nbsp; &nbsp; &nbsp; <groupId>org.springframework.boot</groupId>&nbsp; &nbsp; &nbsp; &nbsp; <artifactId>spring-boot-starter-web</artifactId>&nbsp; &nbsp; </dependency>&nbsp; &nbsp; <dependency>&nbsp; &nbsp; &nbsp; &nbsp; <groupId>com.h2database</groupId>&nbsp; &nbsp; &nbsp; &nbsp; <artifactId>h2</artifactId>&nbsp; &nbsp; &nbsp; &nbsp; <scope>runtime</scope>&nbsp; &nbsp; </dependency>&nbsp; &nbsp; <dependency>&nbsp; &nbsp; &nbsp; &nbsp; <groupId>org.springframework.boot</groupId>&nbsp; &nbsp; &nbsp; &nbsp; <artifactId>spring-boot-starter-test</artifactId>&nbsp; &nbsp; &nbsp; &nbsp; <scope>test</scope>&nbsp; &nbsp; </dependency></dependencies>在pom中添加以下依赖项后,此问题已解决:&nbsp; &nbsp; <dependency>&nbsp; &nbsp; &nbsp; &nbsp; <groupId>javax.xml.bind</groupId>&nbsp; &nbsp; &nbsp; &nbsp; <artifactId>jaxb-api</artifactId>&nbsp; &nbsp; &nbsp; &nbsp; <version>2.3.0</version>&nbsp; &nbsp; </dependency>
打开App,查看更多内容
随时随地看视频慕课网APP