Java 调试 Spring 应用程序的技巧或工具?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/888015/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Tips or tools for debugging Spring applications?
提问by James McMahon
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 调试?
回答by Simon Groenewolt
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?
我通常对日志记录级别也没有问题-您认为它们有什么问题?
回答by Brian Agnew
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.
但是,如果您通过它们的名称(在运行时,使用ApplicationContext.getBean()
)动态解析 bean,那么我可以看到这会导致您在预期控制流等方面出现问题,并建议您重新访问您的 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 源代码非常有用。它很好地组合在一起并且非常可读,因此可能在调试时使用。
回答by toolkit
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 Marketplace 的 Eclipse 帮助菜单中获得)。这将提供代码完成、bean 可视化和热链接到您的配置文件。
回答by Alex
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)一个真正的烦恼是调试器不会在闭包内停止,所以你必须记住在你想要的闭包内放置一个断点检查; 这很好,因为它“几乎”要去一个不同的班级,很多时间都无关紧要,但是当它发生时,你必须记住这一点。