Spring数据存储库在5分钟后被卸载

huangapple 未分类评论87阅读模式
英文:

Spring data repositories get unloaded after 5 minutes

问题

我正在调试一个Spring应用程序,大约在5分钟后会“丢失”它的实体/存储库。

application.properties

spring.datasource.type=com.zaxxer.hikari.HikariDataSource
spring.jpa.database=SYBASE
spring.datasource.driver-class-name=com.sybase.jdbc4.jdbc.SybDriver
spring.datasource.url=jdbc:sybase:Tds:database-host:2638/R4Sybase
spring.datasource.username=user
spring.datasource.password=pass
spring.datasource.maxLifeTime=60000

logging.level.org.springframework.web=DEBUG
logging.level.org.hibernate=DEBUG

spring.jpa.open-in-view=true
spring.jpa.show-sql=false

示例存储库:

public interface EstateRepository extends CrudRepository<Estate, Integer> {
/* ... 无特殊内容 ... */
}

在启动/初始化后,可用的实体在 / 下列出:

{
  "_links" : {
    "estates" : {
      "href" : "http://localhost:8080/choices/estates"
    },
    /* ... 更多实体 ... */
    "profile" : {
      "href" : "http://localhost:8080/choices/profile"
    }
}

然而,大约5分钟后,/ 的响应变成了:

{
  "_links" : {
    "profile" : {
      "href" : "http://localhost:8080/choices/profile"
    }
  }
}

看起来好像所有的实体/存储库都被卸载了,在 catalina 日志中没有任何异常,没有超时,也没有任何数据库错误。在 Tomcat 中重新加载应用程序可以修复问题,但只能持续另外5分钟。

我尝试过调整连接池设置,尝试切换到Tomcat连接池,但都没有成功。

是否有某种保活设置?这是垃圾回收的问题吗?

英文:

I'm debugging a spring application, which "loses" it's Entities/Repositories after ~5 Minutes.

application.properties:

spring.datasource.type=com.zaxxer.hikari.HikariDataSource
spring.jpa.database=SYBASE
spring.datasource.driver-class-name=com.sybase.jdbc4.jdbc.SybDriver
spring.datasource.url=jdbc:sybase:Tds:database-host:2638/R4Sybase
spring.datasource.username=user
spring.datasource.password=pass
spring.datasource.maxLifeTime=60000

logging.level.org.springframework.web=DEBUG
logging.level.org.hibernate=DEBUG

spring.jpa.open-in-view=true
spring.jpa.show-sql=false

Example repository:

public interface EstateRepository extends CrudRepository&lt;Estate, Integer&gt; {
/* ... nothing special ... */
}

After startup/initialization, available entities are listed under /:

{
  &quot;_links&quot; : {
    &quot;estates&quot; : {
      &quot;href&quot; : &quot;http://localhost:8080/choices/estates&quot;
    },
    /* ... more entities ... */
    &quot;profile&quot; : {
      &quot;href&quot; : &quot;http://localhost:8080/choices/profile&quot;
    }
}

However, after ~5 Minutes, the response for /changes to

{
  &quot;_links&quot; : {
    &quot;profile&quot; : {
      &quot;href&quot; : &quot;http://localhost:8080/choices/profile&quot;
    }
  }
}

It seems like all entities/repos are unloaded, there aren't any exceptions in the catalina log, no timeouts, no database errors at all. Reloading the app in tomcat fixes things for another 5 minutes.

I've tried fiddling with connection pool settings, switching to a Tomcat connection pool but to no avail.

Is there some kind of keep-alive setting? Is this a garbage collection issue?

huangapple
  • 本文由 发表于 2020年8月14日 21:30:54
  • 转载请务必保留本文链接:https://java.coder-hub.com/63413769.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定