【问题标题】:Connection with DB stuck spring boot jpa与 DB 连接卡住 spring boot jpa
【发布时间】:2020-11-16 18:40:35
【问题描述】:

当我构建项目时,它卡在 HikariPool-1 - 正在启动...

这是完整的堆栈跟踪:

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.3.5.RELEASE)

2020-11-16 19:25:53.132  INFO 5328 --- [  restartedMain] pl.umcs.lessonwiz.LessonwizApplication   : Starting LessonwizApplication on DESKTOP-4VPS8T4 with PID 5328 (C:\Users\admin\IdeaProjects\lessonwiz\build\classes\java\main starte
d by admin in C:\Users\admin\IdeaProjects\lessonwiz)
2020-11-16 19:25:53.135  INFO 5328 --- [  restartedMain] pl.umcs.lessonwiz.LessonwizApplication   : No active profile set, falling back to default profiles: default
2020-11-16 19:25:53.180  INFO 5328 --- [  restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable
2020-11-16 19:25:53.180  INFO 5328 --- [  restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : For additional web related logging consider setting the 'logging.level.web' property to 'DEBUG'
2020-11-16 19:25:53.688  INFO 5328 --- [  restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFERRED mode.
2020-11-16 19:25:53.706  INFO 5328 --- [  restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 11ms. Found 0 JPA repository interfaces.
2020-11-16 19:25:54.242  INFO 5328 --- [  restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2020-11-16 19:25:54.256  INFO 5328 --- [  restartedMain] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2020-11-16 19:25:54.257  INFO 5328 --- [  restartedMain] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.39]
2020-11-16 19:25:54.351  INFO 5328 --- [  restartedMain] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2020-11-16 19:25:54.352  INFO 5328 --- [  restartedMain] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1172 ms
2020-11-16 19:25:54.434  INFO 5328 --- [  restartedMain] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Starting...

在调试时,我在一个循环中收到 3 条消息:

2020-11-16T19:36:12.936+0100 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Waiting to acquire shared lock on daemon addresses registry.
2020-11-16T19:36:12.936+0100 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Lock acquired on daemon addresses registry.
2020-11-16T19:36:12.936+0100 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Releasing lock on daemon addresses registry.

build.gradle

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
    implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
    implementation 'org.springframework.boot:spring-boot-starter-web'
    developmentOnly 'org.springframework.boot:spring-boot-devtools'
    compile group: 'org.postgresql', name: 'postgresql', version: '42.2.18'
    testImplementation('org.springframework.boot:spring-boot-starter-test') {
        exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
    }
    compileOnly 'org.projectlombok:lombok:1.18.16'
    annotationProcessor 'org.projectlombok:lombok:1.18.16'

    testCompileOnly 'org.projectlombok:lombok:1.18.16'
    testAnnotationProcessor 'org.projectlombok:lombok:1.18.16'
}

application.properties:

spring.output.ansi.enabled=ALWAYS
spring.datasource.url=jdbc:postgresql://127.0.0.1:49888/postgres/postgres
spring.datasource.username=postgres
spring.datasource.password=kurwa123
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
spring.jpa.hibernate.ddl-auto=create

pg面板: Screenshot

感谢您的回答

【问题讨论】:

  • 您的spring.datasource.url 中的postgres 条目似乎过多。您的spring.datasource.url 是否应该最后只有一个postgres
  • 同样的情况,我试过这个只是为了测试
  • 因此,如果您将端口号更改为某个您知道 postgres 未在其上运行的随机端口,您会收到 Connection refused 错误或类似的其他错误吗?
  • 同样的情况,谢谢你的问题解决了我在管理控制台使用的端口上运行应用程序

标签: java database spring-boot hibernate jpa


【解决方案1】:

尝试在application.properties 中更改这些行。

spring.datasource.url=jdbc:postgresql://127.0.0.1:5432/postgres

【讨论】: