私は、Spring 2のフロントエンドを使用するSpringブートWebアプリケーションを持っています。アプリケーションをビルドするときに、クラスパス上の/static/
ディレクトリにあるAngular 2フロントエンドをすべて持っています。そのため、スプリングブートはすべて静的リソースとして機能します。Springブートで静的リソースへのPOST要求を許可しない
私のアプリケーションはIdPに対して認証するためにSAML 2.0を使用し、認証後にIdPがアプリケーションに戻ると、SAML応答を送信するためにPOST要求を送信します。
この結果、405 - メソッドは使用できません。。
スプリングブートで静的リソースにPOSTリクエストを許可する方法はありますか?
POSTリクエストを受け入れるコントローラを追加しようとしても、リクエストをアプリケーションのルートに適切なビューindex.htmlに転送するだけでした。
私は私のapplication.propertiesで次のプロパティを追加しました:
spring.mvc.view.prefix=/static/
spring.mvc.view.suffix=.html
をそして、次のコントローラを追加しました:
@Controller
public class IndexController {
@RequestMapping(value = "/", method = {RequestMethod.GET, RequestMethod.POST})
public String index() {
return "index";
}
}
しかし無駄にします。春のブートは依然としてPOST要求を許可しない静的に処理されたリソースへのリクエストを内部的に解決しました。ここでは春から関連するデバッグメッセージです:
2017-03-22 12:20:56.261 DEBUG [http-nio-8080-exec-6] o.s.web.servlet.DispatcherServlet:865 - DispatcherServlet with name 'dispatcherServlet' processing POST request for [/notification-service/]
2017-03-22 12:20:56.261 DEBUG [http-nio-8080-exec-6] o.s.w.s.m.m.a.RequestMappingHandlerMapping:310 - Looking up handler method for path/
2017-03-22 12:20:56.262 DEBUG [http-nio-8080-exec-6] o.s.w.s.m.m.a.RequestMappingHandlerMapping:317 - Returning handler method [public java.lang.String com.papajohns.corporate.notification.controller.IndexController.index()]
2017-03-22 12:20:56.262 DEBUG [http-nio-8080-exec-6] o.s.b.f.s.DefaultListableBeanFactory:251 - Returning cached instance of singleton bean 'indexController'
2017-03-22 12:20:56.262 DEBUG [http-nio-8080-exec-6] o.s.o.j.s.OpenEntityManagerInViewInterceptor:85 - Opening JPA EntityManager in OpenEntityManagerInViewInterceptor
2017-03-22 12:20:56.263 DEBUG [http-nio-8080-exec-6] o.s.web.cors.DefaultCorsProcessor:71 - Skip CORS processing: response already contains "Access-Control-Allow-Origin" header
2017-03-22 12:20:56.268 DEBUG [http-nio-8080-exec-6] o.s.w.s.v.ContentNegotiatingViewResolver:263 - Requested media types are [text/html, application/xhtml+xml, image/webp, application/xml;q=0.9, */*;q=0.8] based on Accept header types and producible media types [*/*])
2017-03-22 12:20:56.268 DEBUG [http-nio-8080-exec-6] o.s.w.s.view.BeanNameViewResolver:74 - No matching bean found for view name 'index'
2017-03-22 12:20:56.269 DEBUG [http-nio-8080-exec-6] o.s.w.s.view.BeanNameViewResolver:74 - No matching bean found for view name 'index.html'
2017-03-22 12:20:56.269 DEBUG [http-nio-8080-exec-6] o.s.b.f.s.DefaultListableBeanFactory:1670 - Invoking afterPropertiesSet() on bean with name 'index'
2017-03-22 12:20:56.269 DEBUG [http-nio-8080-exec-6] o.s.b.f.s.DefaultListableBeanFactory:251 - Returning cached instance of singleton bean 'org.springframework.transaction.config.internalTransactionAdvisor'
2017-03-22 12:20:56.270 DEBUG [http-nio-8080-exec-6] o.s.b.f.s.DefaultListableBeanFactory:251 - Returning cached instance of singleton bean 'org.springframework.transaction.config.internalTransactionAdvisor'
2017-03-22 12:20:56.274 DEBUG [http-nio-8080-exec-6] o.s.b.f.s.DefaultListableBeanFactory:1670 - Invoking afterPropertiesSet() on bean with name 'index.html'
2017-03-22 12:20:56.274 DEBUG [http-nio-8080-exec-6] o.s.b.f.s.DefaultListableBeanFactory:251 - Returning cached instance of singleton bean 'org.springframework.transaction.config.internalTransactionAdvisor'
2017-03-22 12:20:56.274 DEBUG [http-nio-8080-exec-6] o.s.b.f.s.DefaultListableBeanFactory:251 - Returning cached instance of singleton bean 'org.springframework.transaction.config.internalTransactionAdvisor'
2017-03-22 12:20:56.275 DEBUG [http-nio-8080-exec-6] o.s.w.s.v.ContentNegotiatingViewResolver:338 - Returning [org.springframework.web.servlet.view.InternalResourceView: name 'index'; URL [/static/index.html]] based on requested media type 'text/html'
2017-03-22 12:20:56.276 DEBUG [http-nio-8080-exec-6] o.s.web.servlet.DispatcherServlet:1265 - Rendering view [org.springframework.web.servlet.view.InternalResourceView: name 'index'; URL [/static/index.html]] in DispatcherServlet with name 'dispatcherServlet'
2017-03-22 12:20:56.278 DEBUG [http-nio-8080-exec-6] o.s.w.s.view.InternalResourceView:166 - Forwarding to resource [/static/index.html] in InternalResourceView 'index'
2017-03-22 12:20:56.279 DEBUG [http-nio-8080-exec-6] o.s.web.servlet.DispatcherServlet:865 - DispatcherServlet with name 'dispatcherServlet' processing POST request for [/notification-service/static/index.html]
2017-03-22 12:20:56.280 DEBUG [http-nio-8080-exec-6] o.s.w.s.m.m.a.RequestMappingHandlerMapping:310 - Looking up handler method for path /static/index.html
2017-03-22 12:20:56.282 DEBUG [http-nio-8080-exec-6] o.s.w.s.m.m.a.RequestMappingHandlerMapping:320 - Did not find handler method for [/static/index.html]
2017-03-22 12:20:56.282 DEBUG [http-nio-8080-exec-6] o.s.w.s.h.SimpleUrlHandlerMapping:190 - Matching patterns for request [/static/index.html] are [/**]
2017-03-22 12:20:56.282 DEBUG [http-nio-8080-exec-6] o.s.w.s.h.SimpleUrlHandlerMapping:219 - URI Template variables for request [/static/index.html] are {}
2017-03-22 12:20:56.282 DEBUG [http-nio-8080-exec-6] o.s.w.s.h.SimpleUrlHandlerMapping:140 - Mapping [/static/index.html] to HandlerExecutionChain with handler [ResourceHttpRequestHandler [locations=[ServletContext resource [/], class path resource [META-INF/resources/], class path resource [resources/], class path resource [static/], class path resource [public/]], resolvers=[[email protected]392aa5]]] and 1 interceptor
2017-03-22 12:20:56.283 DEBUG [http-nio-8080-exec-6] o.s.web.cors.DefaultCorsProcessor:71 - Skip CORS processing: response already contains "Access-Control-Allow-Origin" header
2017-03-22 12:20:56.292 DEBUG [http-nio-8080-exec-6] o.s.web.servlet.DispatcherServlet:1044 - Null ModelAndView returned to DispatcherServlet with name 'dispatcherServlet': assuming HandlerAdapter completed request handling
2017-03-22 12:20:56.292 DEBUG [http-nio-8080-exec-6] o.s.web.servlet.DispatcherServlet:1000 - Successfully completed request
2017-03-22 12:20:56.294 DEBUG [http-nio-8080-exec-6] o.s.o.j.s.OpenEntityManagerInViewInterceptor:110 - Closing JPA EntityManager in OpenEntityManagerInViewInterceptor
2017-03-22 12:20:56.295 DEBUG [http-nio-8080-exec-6] o.s.o.jpa.EntityManagerFactoryUtils:435 - Closing JPA EntityManager
2017-03-22 12:20:56.295 DEBUG [http-nio-8080-exec-6] o.s.web.servlet.DispatcherServlet:1000 - Successfully completed request
2017-03-22 12:20:56.295 DEBUG [http-nio-8080-exec-6] o.s.b.w.f.OrderedRequestContextFilter:104 - Cleared thread-bound request context: [email protected]
2017-03-22 12:20:56.295 ERROR [http-nio-8080-exec-6] o.s.boot.web.support.ErrorPageFilter:206 - Cannot forward to error page for request [/] as the response has already been committed. As a result, the response may have the wrong status code. If your application is running on WebSphere Application Server you may be able to resolve this problem by setting com.ibm.ws.webcontainer.invokeFlushAfterService to false
私にも同様の問題があります。 POSTリクエストを通じて静的コンテンツを取得する必要があります。私は古いSpringアプリケーションをSpring Bootに移行しているので、thymeleafは使用できません。何か案が ? – Vins