简体   繁体   English

如何调试@Scheduled spring boot 方法或服务方法?

[英]How to debug a @Scheduled spring boot method or a service method?

I've an existing spring boot application and now I need to debug some methods.我有一个现有的 Spring Boot 应用程序,现在我需要调试一些方法。 Therefore these methods are @Scheduled or in service classes they are invoked automatically by the app.因此,这些方法是@Scheduled或在服务类中,它们由应用程序自动调用。

Is there any option to invoke these methods via debugging?是否有任何选项可以通过调试调用这些方法? Or are there any other ways to do that without changing the source code?或者有没有其他方法可以在不更改源代码的情况下做到这一点? I could add an ApplicationRunner or CommandLineRunner but then I need to change the App sources.我可以添加 ApplicationRunner 或 CommandLineRunner,但随后我需要更改应用程序源。

Thanks谢谢

You can externalize the value for the @Scheduled annotation using SpEL.您可以使用 SpEL 外部化@Scheduled注释的值。 You still need to change the code but afterwards it's configurable and you can change the cron without changing the code.您仍然需要更改代码,但之后它是可配置的,您可以在不更改代码的情况下更改 cron。 That way you can start it with a different cron for debugging too.这样你也可以用不同的 cron 启动它进行调试。

An alternative if you aren't able to change the code is to use remote debugging but you would need to restart the app for that and add the arguments mentioned in this documentation .如果您无法更改代码,另一种方法是使用远程调试,但您需要为此重新启动应用程序并添加本文档中提到的参数。

But that way it may take a lot of time for scheduled methods to get invoked depending on the cron or interval.但是那样的话,根据 cron 或时间间隔,调用预定的方法可能需要很多时间。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM