0

我真的在为弹簧靴和休眠的问题而苦苦挣扎。我收到此错误:

AnnotationConfigServletWebServerApplicationContext - Exception encountered during context initialization - cancelling refresh attempt: 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 javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory

我在想该应用程序无法连接到 mysql 数据库,但似乎并非如此,因为 flyway 能够连接并运行迁移脚本。

[INFO ] 2020-01-21_11:18:39.293 [main] VersionPrinter - Flyway Community Edition 5.0.7 by Boxfuse
[INFO ] 2020-01-21_11:18:39.304 [main] HikariDataSource - HikariPool-1 - Starting...
[INFO ] 2020-01-21_11:18:39.534 [main] HikariDataSource - HikariPool-1 - Start completed.
[INFO ] 2020-01-21_11:18:39.548 [main] DatabaseFactory - Database: jdbc:mysql://someIpHere:3306/someDatabaseNameHere (MySQL 5.6)
[INFO ] 2020-01-21_11:18:40.357 [main] DbValidate - Successfully validated 354 migrations (execution time 00:00.729s)
[INFO ] 2020-01-21_11:18:40.434 [main] DbMigrate - Current version of schema `someDatabaseNameHere `: 339
[WARN ] 2020-01-21_11:18:40.434 [main] DbMigrate - outOfOrder mode is active. Migration of schema `someDatabaseNameHere` may not be reproducible.
[INFO ] 2020-01-21_11:18:40.438 [main] DbMigrate - Schema `someDatabaseNameHere ` is up to date. No migration necessary.
[INFO ] 2020-01-21_11:18:40.622 [main] LocalContainerEntityManagerFactoryBean - Building JPA container EntityManagerFactory for persistence unit 'default'
[INFO ] 2020-01-21_11:18:40.640 [main] LogHelper - HHH000204: Processing PersistenceUnitInfo [
    name: default

奇怪的是,如果我在另一台机器上运行完全相同的 jar,它就可以工作。在我得到错误之前,日志看起来是一样的。

错误日志:

[INFO ] 2020-01-21_11:18:40.622 [main] LocalContainerEntityManagerFactoryBean - Building JPA container EntityManagerFactory for persistence unit 'default'
[INFO ] 2020-01-21_11:18:40.640 [main] LogHelper - HHH000204: Processing PersistenceUnitInfo [
    name: default
    ...]
[INFO ] 2020-01-21_11:18:40.718 [main] Version - HHH000412: Hibernate Core {5.2.14.Final}
[INFO ] 2020-01-21_11:18:40.720 [main] Environment - HHH000206: hibernate.properties not found
[INFO ] 2020-01-21_11:18:40.764 [main] Version - HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
[INFO ] 2020-01-21_11:18:41.242 [main] Dialect - HHH000400: Using dialect: org.hibernate.dialect.MySQL5Dialect
[WARN ] 2020-01-21_11:18:42.253 [main] AnnotationConfigServletWebServerApplicationContext - Exception encountered during context initialization - cancelling refresh attempt: 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 javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory
[INFO ] 2020-01-21_11:18:42.254 [main] HikariDataSource - HikariPool-1 - Shutdown initiated...
[INFO ] 2020-01-21_11:18:42.264 [main] HikariDataSource - HikariPool-1 - Shutdown completed.
[INFO ] 2020-01-21_11:18:42.266 [main] StandardService - Stopping service [Tomcat]

没有错误日志:

[INFO ] 2020-01-21_12:19:31.394 [main] LocalContainerEntityManagerFactoryBean - Building JPA container EntityManagerFactory for persistence unit 'default'
[INFO ] 2020-01-21_12:19:31.417 [main] LogHelper - HHH000204: Processing PersistenceUnitInfo [
    name: default
    ...]
[INFO ] 2020-01-21_12:19:31.510 [main] Version - HHH000412: Hibernate Core {5.2.14.Final}
[INFO ] 2020-01-21_12:19:31.512 [main] Environment - HHH000206: hibernate.properties not found
[INFO ] 2020-01-21_12:19:31.564 [main] Version - HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
[INFO ] 2020-01-21_12:19:31.986 [main] Dialect - HHH000400: Using dialect: org.hibernate.dialect.MySQL5Dialect
[INFO ] 2020-01-21_12:19:34.093 [main] LocalContainerEntityManagerFactoryBean - Initialized JPA EntityManagerFactory for persistence unit 'default'
[INFO ] 2020-01-21_12:19:34.499 [main] cluster - Cluster created with settings {hosts=[someHost:27017, someHost:27017, someHost:27017, someHost:27017, someHost:27017], mode=MULTIPLE, requiredClusterType=UNKNOWN, serverSelectionTimeout='30000 ms', maxWaitQueueSize=500}
[INFO ] 2020-01-21_12:19:34.500 [main] cluster - Adding discovered server someHost:27017 to client view of cluster

我真的坚持这一点。即使以日志记录级别 TRACE 运行,我也找不到 PersistenceException 的实际原因。同样,我在互联网上的任何地方都找不到这种确切的异常行为,大多数情况下它与错误的配置有关,并且日志提供了更多详细信息。它必须与机器有关,但我不知道是什么,也无法从日志中获得更多信息。

4

1 回答 1

0

如果您在外部服务器上运行它,请下载最新版本的 Tomcat。它可能是版本不匹配。这可能会帮助你

于 2020-01-21T18:15:04.567 回答