错误创建使用名称' EntityManagerFactory'在类路径Springboot中定义
尝试了所有可能的解决方案,但无法解决此错误。该应用程序非常基本。当我使用MySQL版本8.0.22时,我使用了MySqldialect 8,但错误仍然存在。解决此问题应采取的措施。这是我遇到错误启动ApplicationContext的错误
。要显示条件报告报告,请启用“调试”重新运行您的应用程序。 2022-07-08 20:28:36.746错误7660 --- [main] osboot.springapplication:应用程序运行失败
org.springframework.beans.beans.beans.factory.beancreatory.beancreationexpection.beancreationexpection:错误创建具有'entityManagerFactory'在类中的bean创建' [org/springframework/boot/autoconfigure/orm/jpa/hibernatejpaconfiguration.class]:init方法的调用失败;嵌套异常是org.hibernate.service.spi.serviceException:无法创建请求的服务[org.hibernate.engine.jdbc.env.spi.jdbcenvironments]
pom.xm.xml.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.1</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<groupId>com.springrest</groupId>
<artifactId>springrest</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>springrest</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>17</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
/strong>
server.port=8050
#database configuration:mysql
spring.datasource.url=jdbc:mysql://localhost:3306/sampledb
spring.datasource.username=root
spring.datasource.password=password
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
#Hibernate config
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.dialect="org.hibernate.dialect,MySQL8Dialect"
spring.jpa.properties.hibernate.temp.use_jdbc_metadata_defaults=false
course.java
@Entity
public class Course {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "<seq name in java in generator anno>")
@SequenceGenerator(name = "<seq name in java in generator anno>", sequenceName = "<seq name in db>", allocationSize = 1)
private int id;
private String title;
private String desc;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getDesc() {
return desc;
}
public void setDesc(String desc) {
this.desc = desc;
}
public Course() {
super();
}
public Course(int id, String title, String desc) {
super();
this.id = id;
this.title = title;
this.desc = desc;
}
}
Tried all possible solutions but can't resolve this error. The application is very basic. I have used MySQLDialect 8 as I use mysql version 8.0.22 but still the error persists. What shall be done to resolve this issue. This is the error that I am getting
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2022-07-08 20:28:36.746 ERROR 7660 --- [ main] o.s.boot.SpringApplication : Application run failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Invocation of init method failed; nested exception is org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.1</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<groupId>com.springrest</groupId>
<artifactId>springrest</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>springrest</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>17</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
application.properties
server.port=8050
#database configuration:mysql
spring.datasource.url=jdbc:mysql://localhost:3306/sampledb
spring.datasource.username=root
spring.datasource.password=password
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
#Hibernate config
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.dialect="org.hibernate.dialect,MySQL8Dialect"
spring.jpa.properties.hibernate.temp.use_jdbc_metadata_defaults=false
Course.java
@Entity
public class Course {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "<seq name in java in generator anno>")
@SequenceGenerator(name = "<seq name in java in generator anno>", sequenceName = "<seq name in db>", allocationSize = 1)
private int id;
private String title;
private String desc;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getDesc() {
return desc;
}
public void setDesc(String desc) {
this.desc = desc;
}
public Course() {
super();
}
public Course(int id, String title, String desc) {
super();
this.id = id;
this.title = title;
this.desc = desc;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您制作了错别字并用过“”,而不是“”。
尝试将“ org.hibernate.dialect,mysql8dialect”更改为“配置文件中的org.hibernate.dialect.mysql8dialect”。
检查数据库URL是否正确,以及数据库是否启动并运行。还要检查您的用户名和密码是否正确。
I think you've made a typo and used "," instead of ".".
Try changing "org.hibernate.dialect,MySQL8Dialect" to "org.hibernate.dialect.MySQL8Dialect" in your configuration file.
Check if your database URL is correct and if your database is up and running. Also check if your username and password are correct.