调试Spring应用程序的提示或工具?

时间:2022-09-19 06:10:26

I am trying to use Spring for the first time in an application. The general issue that comes up repeatedly is how to debug Spring. The framework is configuration heavy so traditional code debugging seems fruitless. I have no real idea how to go about troubleshooting short of turning on the debugging level logs (which are lacking) and scanning through.

我试图在应用程序中第一次使用Spring。反复出现的一般问题是如何调试Spring。该框架配置繁重,因此传统的代码调试似乎毫无结果。我不知道如何在没有打开调试级别日志(缺少)和扫描的情况下进行故障排除。

Are there any general tips or tools to assist Spring debugging?

是否有任何一般提示或工具可以帮助Spring调试?

4 个解决方案

#1


If you're using Eclipse, then get hold of the Spring IDE (available from the Eclipse Marketplace within the Help menu of Eclipse). This will provide code-completion, bean visualisation, and hot-linking to your config files.

如果您正在使用Eclipse,那么请掌握Spring IDE(可从Eclipse的“帮助”菜单中的Eclipse Marketplace获得)。这将为您的配置文件提供代码完成,bean可视化和热链接。

#2


I don't think Spring debugging should be any different to any other debugging scenario.

我不认为Spring调试应该与任何其他调试方案有任何不同。

What aspects of Spring are you using ? If you're using dependency injection properly, then I wouldn't anticipate any problems.

您使用Spring的哪些方面?如果您正确使用依赖注入,那么我不会预料到任何问题。

However if you're dynamically resolving beans via their name (at runtime, using ApplicationContext.getBean()) then I can see that's going to cause you problems anticipating flow of control etc., and would suggest that you revisit your IoC.

但是,如果您通过名称动态解析bean(在运行时,使用ApplicationContext.getBean()),那么我可以看到这会导致您在预测控制流等方面出现问题,并建议您重新访问IoC。

EDIT: It's quite useful to have the Spring source code available. It's well put together and quite readable, and therefore possibly of use when debugging.

编辑:使用Spring源代码非常有用。它很好地组合在一起并且非常易读,因此可能在调试时使用。

#3


I generally just use the java debugger in eclipse - it works fine on most classes. Some classes are wrapped at compile/runtime by bytecode changes - for these you generally cannot put breakpoints in methods, however you can set a breakpoint at method entry.

我通常只是在eclipse中使用java调试器 - 它在大多数类中都能正常工作。有些类在编译/运行时通过字节码更改包装 - 对于这些类,通常不能在方法中放置断点,但是可以在方法入口处设置断点。

If you have a very specific situation you maybe should elaborate a bit in your question.

如果你有一个非常具体的情况,你可能应该在你的问题中详细说明。

I'm generally also ok with the logging levels - what do you think is wrong with them?

我一般也对日志记录级别没问题 - 你认为它们有什么问题?

#4


As of 09/2011 (Version: 2.6.1.RELEASE, Build Id: 201105041000) a real annoyance is the fact that the debugger doesn't stop inside closures, so you have to remember to put a breakpoint inside the ones you want to examine; that is fine as it is "almost" going to a different class which a lot of time doens't matter, but when it does, you have to remember that.

截至09/2011(版本:2.6.1.RELEASE,Build Id:201105041000)真正的烦恼是调试器不会在闭包内停止,所以你必须记住在你想要的内部放置一个断点检查;这很好,因为它“几乎”去了一个很多时间并不重要的不同的课程,但是当它确实如此时,你必须记住这一点。

#1


If you're using Eclipse, then get hold of the Spring IDE (available from the Eclipse Marketplace within the Help menu of Eclipse). This will provide code-completion, bean visualisation, and hot-linking to your config files.

如果您正在使用Eclipse,那么请掌握Spring IDE(可从Eclipse的“帮助”菜单中的Eclipse Marketplace获得)。这将为您的配置文件提供代码完成,bean可视化和热链接。

#2


I don't think Spring debugging should be any different to any other debugging scenario.

我不认为Spring调试应该与任何其他调试方案有任何不同。

What aspects of Spring are you using ? If you're using dependency injection properly, then I wouldn't anticipate any problems.

您使用Spring的哪些方面?如果您正确使用依赖注入,那么我不会预料到任何问题。

However if you're dynamically resolving beans via their name (at runtime, using ApplicationContext.getBean()) then I can see that's going to cause you problems anticipating flow of control etc., and would suggest that you revisit your IoC.

但是,如果您通过名称动态解析bean(在运行时,使用ApplicationContext.getBean()),那么我可以看到这会导致您在预测控制流等方面出现问题,并建议您重新访问IoC。

EDIT: It's quite useful to have the Spring source code available. It's well put together and quite readable, and therefore possibly of use when debugging.

编辑:使用Spring源代码非常有用。它很好地组合在一起并且非常易读,因此可能在调试时使用。

#3


I generally just use the java debugger in eclipse - it works fine on most classes. Some classes are wrapped at compile/runtime by bytecode changes - for these you generally cannot put breakpoints in methods, however you can set a breakpoint at method entry.

我通常只是在eclipse中使用java调试器 - 它在大多数类中都能正常工作。有些类在编译/运行时通过字节码更改包装 - 对于这些类,通常不能在方法中放置断点,但是可以在方法入口处设置断点。

If you have a very specific situation you maybe should elaborate a bit in your question.

如果你有一个非常具体的情况,你可能应该在你的问题中详细说明。

I'm generally also ok with the logging levels - what do you think is wrong with them?

我一般也对日志记录级别没问题 - 你认为它们有什么问题?

#4


As of 09/2011 (Version: 2.6.1.RELEASE, Build Id: 201105041000) a real annoyance is the fact that the debugger doesn't stop inside closures, so you have to remember to put a breakpoint inside the ones you want to examine; that is fine as it is "almost" going to a different class which a lot of time doens't matter, but when it does, you have to remember that.

截至09/2011(版本:2.6.1.RELEASE,Build Id:201105041000)真正的烦恼是调试器不会在闭包内停止,所以你必须记住在你想要的内部放置一个断点检查;这很好,因为它“几乎”去了一个很多时间并不重要的不同的课程,但是当它确实如此时,你必须记住这一点。

相关文章