如何调试Spring注释?

时间:2022-10-30 14:45:06

I have been using annotations on my Spring Boot project, and they are black boxes to me. Unfortunately, I ran into an issue with the annotations and had no idea how to track down the issue. I was using the @PageableDefault annotation on my controller method with the @RepositoryRestController annotation at the class level, which resulted in my Pageable object to be null under Spring Boot 1.4.1. If I used @Controller, my pageable object would be populated correct. This ended up being a bug DATAREST-906 in Spring Data Rest and fixed in Spring Boot 1.4.2.

我一直在Spring Boot项目上使用注释,它们对我来说都是黑盒子。不幸的是,我遇到了注释的问题,并且不知道如何追踪问题。我在我的控制器方法上使用@PageableDefault注释,在类级别使用@RepositoryRestController注释,这导致我的Pageable对象在Spring Boot 1.4.1下为null。如果我使用@Controller,我的可分页对象将被填充正确。这最终成为Spring Data Rest中的一个错误DATAREST-906,并在Spring Boot 1.4.2中得到修复。

As a use case above what should I have done to debug this issue? Where should I have put my breakpoint to go down the rabbit hole?

作为上面的一个用例,我应该怎么做来调试这个问题?我应该把断点放在兔子洞里?

1 个解决方案

#1


2  

You need to find the code that actually checks for the annotation and executes some logic based on it. This could theoretically happen in several places. If you search for occurrences of WhateverAnnotation.class in the source code you can find those places. You can also put breakpoints there, if you've linked the source properly in your IDE.

您需要找到实际检查注释的代码并根据它执行一些逻辑。理论上这可能发生在几个地方。如果在源代码中搜索WhateverAnnotation.class的出现位置,则可以找到这些位置。如果您已在IDE中正确链接源,则还可以在其中放置断点。

#1


2  

You need to find the code that actually checks for the annotation and executes some logic based on it. This could theoretically happen in several places. If you search for occurrences of WhateverAnnotation.class in the source code you can find those places. You can also put breakpoints there, if you've linked the source properly in your IDE.

您需要找到实际检查注释的代码并根据它执行一些逻辑。理论上这可能发生在几个地方。如果在源代码中搜索WhateverAnnotation.class的出现位置,则可以找到这些位置。如果您已在IDE中正确链接源,则还可以在其中放置断点。