英文:
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<Estate, Integer> {
/* ... nothing special ... */
}
After startup/initialization, available entities are listed under /
:
{
"_links" : {
"estates" : {
"href" : "http://localhost:8080/choices/estates"
},
/* ... more entities ... */
"profile" : {
"href" : "http://localhost:8080/choices/profile"
}
}
However, after ~5 Minutes, the response for /
changes to
{
"_links" : {
"profile" : {
"href" : "http://localhost:8080/choices/profile"
}
}
}
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?
专注分享java语言的经验与见解,让所有开发者获益!
评论