找到此类问题的一种方法是亲自查看。这是 Eclipse 的示例,但它对于其他 IDE 的工作方式应该类似:
首先,确保您拥有正在使用的 spring 库的源代码。如果你使用maven,这是最简单的,使用 maven-eclipse-plugin http://maven.apache.org/plugins/maven-eclipse-plugin/examples/attach-library-sources.html或使用m2eclipse http://m2eclipse.sonatype.org/.
然后,在 Eclipse 中选择Navigate -> Open Type...
。输入您要查找的类型(例如RequestMa*
应该适合像我这样的懒打字员)。输入/确定。现在右键单击源文件中的类名并选择References -> Project
。在搜索视图中,将显示此类或注释的所有使用。
其中之一是DefaultAnnotationHandlerMapping.defineUrlsForHandlerMethods(类,布尔值) http://static.springsource.org/spring/docs/3.0.x/javadoc-api/org/springframework/web/servlet/mvc/annotation/DefaultAnnotationHandlerMapping.html#determineUrlsForHandlerMethods%28java.lang.Class,%20boolean%29,其中此代码片段将告诉您表达式语言未求值:
ReflectionUtils.doWithMethods(currentHandlerType, new ReflectionUtils.MethodCallback() {
public void doWith(Method method) {
RequestMapping mapping = AnnotationUtils.findAnnotation(
method, RequestMapping.class);
if (mapping != null) {
String[] mappedPatterns = mapping.value();
if (mappedPatterns.length > 0) {
for (String mappedPattern : mappedPatterns) {
// this is where Expression Language would be parsed
// but it isn't, as you can see
if (!hasTypeLevelMapping && !mappedPattern.startsWith("/")) {
mappedPattern = "/" + mappedPattern;
}
addUrlsForPath(urls, mappedPattern);
}
}
else if (hasTypeLevelMapping) {
urls.add(null);
}
}
}
}, ReflectionUtils.USER_DECLARED_METHODS);
请记住,它称为开源。如果您不尝试了解自己正在使用什么,那么使用开源软件就没有意义。