我有一个基于RESTful spring的端点,可以将存储在db中的资源存储到javascript编辑器中.相关部分归结为:
@RestController
@RequestMapping(ThemeEndpoint.ENDPOINT_NAME)
public class ThemeEndpoint {
public static final String ENDPOINT_NAME = "/themes";
@RequestMapping(value="/{id}/css/{assetName:.*}", method=RequestMethod.GET)
public Asset getCssItem(
@PathVariable("id") ThemeId id,
@PathVariable("assetName") String name) {
CssThemeAsset themeAsset = themeService.getCssAsset(
id, ThemeAssetId.fromString(name));
Asset asset = new Asset();
asset.name = themeAsset.getName();
asset.text = themeAsset.getContent();
return asset;
}
Run Code Online (Sandbox Code Playgroud)
对于像这样的网址,这可以正常工作
http://localhost:8080/app-url/rest/themes/ac18a080-a2f1-11e3-84f4-600308a0bd14/css/main.less
Run Code Online (Sandbox Code Playgroud)
但是一旦我将扩展名更改为,就会失败.css.
经过一些调试后,我非常确定如果我使用的是url,请求甚至都没有映射
http://localhost:8080/app-url/rest/themes/ac18a080-a2f1-11e3-84f4-600308a0bd14/css/main.css
Run Code Online (Sandbox Code Playgroud)
对于高日志级别,我可以看到映射是由spring捕获的:
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping
- Mapped "{[/themes/{id}/css/{assetName:.*}],methods=[GET],params=[],headers=[],
consumes=[],produces=[application/json],custom=[]}"
onto public xxx.endpoint.ThemeEndpoint$Asset
xxx.endpoint.ThemeEndpoint.getCssItem(
net.lacho.svc.themes.api.ThemeId,java.lang.String)
Run Code Online (Sandbox Code Playgroud)
并且使用非.css扩展名调用控制器:
Found 1 matching mapping(s) for [/themes/ac18a080-a2f1-11e3-84f4-600308a0bd14/css/main.less]
: [{[/themes/{id}/css/{assetName:.*}],methods=[GET],params=[],headers=[],
consumes=[],produces=[application/json],custom=[]}]
Run Code Online (Sandbox Code Playgroud)
但是只要我使用.css作为扩展名 - bang:
Looking up …Run Code Online (Sandbox Code Playgroud) 我发现了Spring MVC的一个非常奇怪的行为.
我有控制器方法:
@RequestMapping (value = "/delete/{id:.*}", method = RequestMethod.DELETE)
public ResponseEntity<Response> delete(@PathVariable (value = "id") final String id) {
HttpStatus httpStatus = HttpStatus.OK;
final Response responseState = new Response( ResponseConstants.STATUS_SUCCESS );
try {
POJO pojo = mediaFileDao.findById( id );
if (pojo != null) {
delete(pojo);
} else {
httpStatus = HttpStatus.NOT_FOUND;
responseState.setError( "NOT_FOUND" );
}
} catch (Exception e) {
httpStatus = HttpStatus.INTERNAL_SERVER_ERROR;
responseState.setError( e.getMessage() );
}
return new ResponseEntity<>( responseState, httpStatus );
}
Run Code Online (Sandbox Code Playgroud)
所以,问题是当id包含点(例如"my_file.wav")时,Spring在任何情况下都会返回HTTP 406,但是如果id不包含点,则Spring会按照我的方式返回responseState(作为json).我尝试以不同的方式修复它(添加@ResponseBody,更改jackson版本,将Spring降级到4.0)但没有任何结果.
谁能帮我?
更新我为Spring …