Spring Boot 2.3.x 应用程序卡在启动时

标签 spring spring-boot spring-data-jpa

我有一个带有以下 spring 自动配置的标准 spring boot 应用程序

    implementation 'org.springframework.boot:spring-boot-starter-actuator'
    implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
    implementation 'org.springframework.boot:spring-boot-starter-web'
    implementation 'org.springframework.boot:spring-boot-starter-validation'

在我创建第一个实体和存储库以及引用它们的服务之前,该应用程序运行良好:

@Entity
@Table(name = "xxx")
public class XXX extends AuditingEntity{


@Repository
public interface XXXRepository extends CrudRepository<XXX, Integer> {

}

@Service
public class XXXService {

    @Resource
    XXXRepository xxxRepository;
    ...

应用程序启动失败,一直卡在后面,从不在前面

2020-06-15 15:48:23.826  INFO [xxx,,,] 2882 --- [           main] o.f.c.internal.license.VersionPrinter    : Flyway Community Edition 6.4.4 by Redgate
2020-06-15 15:48:23.911  INFO [xxx,,,] 2882 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Starting...
2020-06-15 15:48:24.161  INFO [xxx,,,] 2882 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Start completed.
2020-06-15 15:48:24.222  INFO [xxx,,,] 2882 --- [           main] o.f.c.internal.database.DatabaseFactory  : Database: jdbc:mysql://localhost/xxx (MySQL 5.7)
2020-06-15 15:48:24.387  INFO [xxx,,,] 2882 --- [           main] o.f.core.internal.command.DbValidate     : Successfully validated 2 migrations (execution time 00:00.062s)
2020-06-15 15:48:24.434  INFO [xxx,,,] 2882 --- [           main] o.f.core.internal.command.DbMigrate      : Current version of schema `xxx`: 0.0.1
2020-06-15 15:48:24.437  INFO [xxx,,,] 2882 --- [           main] o.f.core.internal.command.DbMigrate      : Schema `xxx` is up to date. No migration necessary.
2020-06-15 15:48:24.621  INFO [xxx,,,] 2882 --- [           main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'
2020-06-15 15:48:24.812  WARN [xxx,,,] 2882 --- [           main] JpaBaseConfiguration$JpaWebConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning


我一直在使用早期版本的 spring boot 很长一段时间,有人知道如何修复它吗?

最佳答案

这很可能是由这个错误引起的:https://github.com/spring-projects/spring-framework/issues/25111

The problem is caused by Spring Boot 2.3 moving to bootstrapping Hibernate asynchronously by default. [...] Bootstrapping results in a call back into the bean factory via SpringBeanContainer and a deadlock occurs. [...] In the meantime, you can avoid the problem by disabling deferred bootstrapping:

spring:
  data:
    jpa:
      repositories:
        bootstrap_mode: default

关于Spring Boot 2.3.x 应用程序卡在启动时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62381139/

相关文章:

java - 为什么 Eclipse 不会在断点处停止?

Spring @IfProfileValue 应该忽略测试类,但事实并非如此

java - 部署 Spring Boot + Angular 应用程序时出现的问题

java - Spring数据JPA : InvalidDataAccessApiUsageException for @Transactional

java - 当我通过 JPA 运行查询时出现 MissingTokenException

java - 加密和解密密码并通过 http 共享

java - JUnit 和 Spring : Cannot find persistence. xml - 但它确实存在

java - 在 spring 中获取 application.yml 信息

java - spring boot h2 无法创建数据库并登录 h2-console

java - HA-JDBC 与 Spring Boot JPA 集成