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

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

Spring data repositories get unloaded after 5 minutes

问题

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

application.properties

  1. spring.datasource.type=com.zaxxer.hikari.HikariDataSource
  2. spring.jpa.database=SYBASE
  3. spring.datasource.driver-class-name=com.sybase.jdbc4.jdbc.SybDriver
  4. spring.datasource.url=jdbc:sybase:Tds:database-host:2638/R4Sybase
  5. spring.datasource.username=user
  6. spring.datasource.password=pass
  7. spring.datasource.maxLifeTime=60000
  8. logging.level.org.springframework.web=DEBUG
  9. logging.level.org.hibernate=DEBUG
  10. spring.jpa.open-in-view=true
  11. spring.jpa.show-sql=false

示例存储库:

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

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

  1. {
  2. "_links" : {
  3. "estates" : {
  4. "href" : "http://localhost:8080/choices/estates"
  5. },
  6. /* ... 更多实体 ... */
  7. "profile" : {
  8. "href" : "http://localhost:8080/choices/profile"
  9. }
  10. }

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

  1. {
  2. "_links" : {
  3. "profile" : {
  4. "href" : "http://localhost:8080/choices/profile"
  5. }
  6. }
  7. }

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

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

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

英文:

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

application.properties:

  1. spring.datasource.type=com.zaxxer.hikari.HikariDataSource
  2. spring.jpa.database=SYBASE
  3. spring.datasource.driver-class-name=com.sybase.jdbc4.jdbc.SybDriver
  4. spring.datasource.url=jdbc:sybase:Tds:database-host:2638/R4Sybase
  5. spring.datasource.username=user
  6. spring.datasource.password=pass
  7. spring.datasource.maxLifeTime=60000
  8. logging.level.org.springframework.web=DEBUG
  9. logging.level.org.hibernate=DEBUG
  10. spring.jpa.open-in-view=true
  11. spring.jpa.show-sql=false

Example repository:

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

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

  1. {
  2. &quot;_links&quot; : {
  3. &quot;estates&quot; : {
  4. &quot;href&quot; : &quot;http://localhost:8080/choices/estates&quot;
  5. },
  6. /* ... more entities ... */
  7. &quot;profile&quot; : {
  8. &quot;href&quot; : &quot;http://localhost:8080/choices/profile&quot;
  9. }
  10. }

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

  1. {
  2. &quot;_links&quot; : {
  3. &quot;profile&quot; : {
  4. &quot;href&quot; : &quot;http://localhost:8080/choices/profile&quot;
  5. }
  6. }
  7. }

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:

确定