Java Spring Scheduler在PCF服务器中不起作用。

huangapple go评论94阅读模式
英文:

Java Spring Scheduler not working in PCF server

问题

在我的 Spring Boot 项目中,Spring 调度程序正常工作,因为我已经在本地系统中的调度程序方法中使用 Cron 表达式添加了日志记录。

问题:

当相同的 Spring Boot 应用部署在 PCF(Pivotal Cloud Foundry)上时,它不会启用调度程序,既不会打印任何日志,也不会显示与调度程序相关的任何错误日志。

而当我通过 Postman 发送请求到任何控制器时,会打印出日志,但调度程序的日志却不会打印出来。

我还在 PCF 的环境变量中提供了类似每分钟一次的 Cron 表达式值,并重新启动了应用。但这并没有帮助。

有人能在这个问题上给我一些建议吗?

非常感谢您宝贵的时间!!

英文:

I have a spring boot project in which spring scheduler is working fine as i have added logger in scheduler method in my local system using Cron expression.

Problem:

When same spring boot app is deployed over PCF(Pivotal Cloud Foundary) it does not enable the scheduler and no logs are printed neither any error is shown in pcf logs related to scheduler.

While if i hit any controller through postman, logs are printing for that but not of scheduler.

I also provided cron expression value like for every minute in pcf environment variables in app and restarted the app. But that didn't help.

Can anyone suggest me something in this issue?

Thank you in advance for your valuable time!!

答案1

得分: 1

当您将应用程序部署在PCF云空间中时,它会获取您的代码,根据用户提供的显式构建包或可用构建包进行扫描,然后使用代码、构建包和基础容器创建一个被称为Droplet的容器映像。

如果您使用云配置来管理Spring Boot调度程序的配置,则它会使用自动配置来在运行时加载属性。在某些情况下,由于操作系统配置和运行时加载这些配置的差异,您的应用程序期望的时区与服务器理解的时区可能不匹配。

大多数情况下,可以通过在PCF清单文件或在推送应用程序时的命令行中显式定义时区配置来解决这个问题。

例如,设置环境变量TZ。

cf set-env {app-name} TZ 'America/Chicago'

或者在manifest.yml文件中添加以下内容:

env:
TZ: America/Chicago

英文:

When you deploy your application in PCF Cloud space, it takes your code, scan it against available buildpacks unless explicitly provided by user and then creates a container image also known as Droplet using code, build-pack and base container.

If you use cloud config to manage the configurations for spring boot scheduler, it uses auto configurations to load the properties at runtime. In some cases due to the difference in the OS configuration and loading of these configurations at runtime, there will be mismatch between what timezone your app expects and the one that the server understands.

Most of the time it can be resolved by explicitly defining the timezone configuration in PCF manifest file or command line when pushing the application.

E.g. set environment TZ variable.

cf set-env {app-name} TZ 'America/Chicago'

OR by adding following in manifest.yml file:

env:
TZ: America/Chicago

huangapple
  • 本文由 发表于 2020年4月8日 01:46:11
  • 转载请务必保留本文链接:https://go.coder-hub.com/61086181.html
匿名

发表评论

匿名网友

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

确定