我有一个使用基本身份验证运行spring security的spring boot应用程序.当提供适当的基本身份验证凭据时,一切都很好,但是对于不正确的身份验证凭据,spring会出现HttpRequestMethodNotSupportedException: Request method 'POST' not supported异常.
根据日志,Spring已经确定了身份验证失败,但这并不是出现的问题.
2015-08-12 09:33:10.922 INFO 16988 --- [nio-8080-exec-4] o.s.b.a.audit.listener.AuditListener : AuditEvent [timestamp=Wed Aug 12 09:33:10 AEST 2015, principal=anonymousUser, type=AUTHORIZATION_FAILURE, data={type=org.springframework.security.access.AccessDeniedException, message=Access is denied}]
2015-08-12 09:33:10.927 TRACE 16988 --- [nio-8080-exec-4] o.s.web.servlet.DispatcherServlet : Bound request context to thread: FirewalledRequest[ org.apache.catalina.core.ApplicationHttpRequest@483e1fc6]
2015-08-12 09:33:10.927 DEBUG 16988 --- [nio-8080-exec-4] o.s.web.servlet.DispatcherServlet : DispatcherServlet with name 'dispatcherServlet' processing POST request for [/myapplication/error]
2015-08-12 09:33:10.927 TRACE 16988 --- [nio-8080-exec-4] o.s.web.servlet.DispatcherServlet : Testing handler map [org.springframework.web.servlet.handler.SimpleUrlHandlerMapping@331bb032] in DispatcherServlet with name …
security authentication spring credentials basic-authentication
在我的Spring XML中,我有以下代码段:
<bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping">
<property name="useDefaultSuffixPattern" value="false"/>
</bean>
<mvc:annotation-driven>
<mvc:message-converters>
<bean class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter">
<property name="objectMapper" ref="objectMapper" />
</bean>
</mvc:message-converters>
</mvc:annotation-driven>
Run Code Online (Sandbox Code Playgroud)
据我了解,这意味着春天应该不登记"ABC*"和"ABC /"当我有"ABC"的映射.
在我的一个控制器中,我有一个将图像写入响应的方法:
@RequestMapping(value="{path}", method=RequestMethod.GET, produces=MediaType.IMAGE_PNG_VALUE)
@ResponseBody
public void getPath(
@PathVariable String path,
HttpServletResponse res) {
...
}
Run Code Online (Sandbox Code Playgroud)
当我请求像"abc"这样的东西时,这很有用,但是当我请求"abc.com"时,它会在文本中抛出406错误:
The resource identified by this request is only capable of generating responses with characteristics not acceptable according to the request "accept" headers."
Run Code Online (Sandbox Code Playgroud)
当我请求"abc.img"时,"path"参数只接收文本"abc"; Spring省略了扩展名.
看来Spring似乎没有正确地忽略后缀模式.为什么是这样?
编辑:我从Dirk的评论中翻译了java配置,以下XML似乎解决了这个问题:
<bean id="contentNegotiationManager" class="org.springframework.web.accept.ContentNegotiationManagerFactoryBean">
<property name="favorPathExtension" value="false" />
</bean>
<mvc:annotation-driven content-negotiation-manager="contentNegotiationManager">
<mvc:message-converters>
<bean …Run Code Online (Sandbox Code Playgroud) 我的开发环境在代理后面,所以我需要将代理信息设置为其余模板,当我使用 HttpComponentsClientHttpRequestFactory 并在 httpClient 中设置代理设置并将其设置在模板中时,这一切都很好。
但是现在我有一个需要基本身份验证的休息服务。要设置基本身份验证凭据,我需要在其余模板的 httpClient 中设置它们。但是我看到 httpClient 中的 getparams 方法已被弃用,所以我不能只更新模板中的现有客户端,如果我创建一个新的 httpclient 对象,我将覆盖在应用程序引导期间设置的代理信息。
那么有什么方法可以从其余模板中提取 httpClient 并更新它吗?或者有没有其他方法可以解决这个问题?
谢谢。