【发布时间】:2019-06-29 09:08:23
【问题描述】:
我有一个 Spring Boot 项目。我将我的项目远程部署为 tomcat 的 jar。我在远程服务器上运行以部署 jar 的脚本:
#!/bin/sh
/usr/local/java8/jdk1.8.0_71/bin/java -jar -Duser.timezone=Europe/Athens example.jar> log.out
整个项目运行良好,但有时会自动调用 Web 服务,而无需我做任何事情或让调度程序调用它们。
例如我的控制器类中的一个方法
@RequestMapping(value = "/heartbeat")
public ResponseEntity<String> heartbeat() {
Log.info("heartbeat");
return new ResponseEntity<>("success", org.springframework.http.HttpStatus.OK);
}
当项目被远程部署时,我可以从日志中看到该方法每分钟都会被调用一次,即使没有人调用它:
02/05/19 15:23:22.721 信息 http-nio-8044-exec-9 TestController:238 - 心跳
02/05/19 15:24:22.133 信息 http-nio-8044-exec-1 TestController:238 - 心跳
02/05/19 15:25:22.426 信息 http-nio-8044-exec-8 TestController:238 - 心跳
02/05/19 15:26:22.782 信息 http-nio-8044-exec-7 TestController:238 - 心跳
02/05/19 15:27:22.179 信息 http-nio-8044-exec-5 TestController:238 - 心跳
在我的 pom 和属性中,我找不到与调度程序相关的内容。我的控制器方法也没有用@Scheduled 注释。有什么想法吗?
application.properties
management.context-path=/internal/manage
management.security.enabled=false
endpoints.health.id = health
endpoints.health.sensitive = true
endpoints.health.enabled = true
endpoints.info.id=info
endpoints.info.sensitive=false
endpoints.info.enabled=true
info.app.name=Test app name
info.app.description=Test project
endpoints.actuator.enabled=true
spring.application.admin.enabled=true
endpoints.hypermedia.enabled=true
management.info.git.mode=full
【问题讨论】:
-
这很难回答。但是您可以从分析请求开始。如果它只发生在远程,您可以添加更多日志记录,让您深入了解请求。
RequestContext是你的朋友。 -
我知道这很难回答,但我不得不问,因为我发现这不可能。它只是远程发生的,所以是的,我会尝试看看 HttpServletRequest 和更多日志发生了什么。
-
知道我应该从 RequestContext 中检查什么吗?
-
你在使用 Kubernetes 吗?还是使用执行器进行健康检查?
-
恒定的轮询频率表明负载均衡器会测试您是否还活着。如果这是一个云环境,它可能在您不知道的情况下就在那里。在 heartbeat() 调用中记录调用者的 IP 地址和所有请求标头并进行追溯。
标签: java spring spring-boot tomcat jar