(我无法在当前的JRebel 6.1.1中重现 )-我猜 已修复(2014年12月23日)
修复了Spring ResourceHttpRequestHandler无法为webroot之外的资源提供服务的问题。
(JRebel Changeloghttps://zeroturnaround.com/software/jrebel/download/changelog/6-x/)
对于感兴趣的人如何解决它:
我只能猜测,因为这很奇怪。Spring 4.1.6(即我用于测试的版本)的类org.springframework.web.servlet.resource.PathResourceResolver
具有方法checkResource(Resource resource, Resource location)
:
protected boolean checkResource(Resource resource, Resource location) throws IOException {
if (isResourceUnderLocation(resource, location)) {
return true;
}
if (getAllowedLocations() != null) {
for (Resource current : getAllowedLocations()) {
if (isResourceUnderLocation(resource, current)) {
return true;
}
}
}
return false;
}
第一种if
:isResourceUnderLocation...
检查请求是否正在访问已配置资源文件夹之外的资源的方法
isResourceUnderLocation(Resource resource, Resource location) {
...
resourcePath = ((ServletContextResource) resource).getPath();
locationPath = StringUtils.cleanPath(((ServletContextResource) location).getPath());
...
if (!resourcePath.startsWith(locationPath)) {
return false;
}
...
}
当我使用调试器检查JRebel处于活动状态时,发生了什么事情时,发生了一些奇怪的事情:当JVM上线时if (isResourceUnderLocation(resource, location)) {
,该方法isResourceUnderLocation
就不会被调用!
因此,我得出的结论是,JRebel进行了一些字节码操作,以防止执行检查(以及整个isResourceUnderLocation
方法)。