记一次上线出现的问题-----org.springframework.web.util.WebUtils.isSameOrigin(WebUtils.java:816)的解决方法(nginx配置问题)

项目发布到预发布环境,出现了问题。因为项目是要登录才能进系统,但是怎么都登录不成功,报空指针的异常,并且申请账号也报空指针异常。关键测试环境没问题,同一套代码。所以,问题肯定出在了代码以外的地方,先贴下错误日志:
[2018-06-04 16:50:37,364][INFO ][c14119a316f948f6807ec4841cceeec9][`:29] process time: 1 ms @com.tclshop.front.rest.login.TclStaffLoginController.checkImageValidateCode[2018-06-04 16:50:37,393][ERROR][33018b7b35d0463cba82f8b11a3ae495][ErrorInterceptor:42] nulljava.lang.NullPointerException: null at org.springframework.web.util.WebUtils.isSameOrigin(WebUtils.java:816) at org.springframework.web.cors.DefaultCorsProcessor.processRequest(DefaultCorsProcessor.java:76) at org.springframework.web.servlet.handler.AbstractHandlerMapping$CorsInterceptor.preHandle(AbstractHandlerMapping.java:503) at org.springframework.web.servlet.HandlerExecutionChain.applyPreHandle(HandlerExecutionChain.java:134) at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:956) at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:895) at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:967) at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:869) at javax.servlet.http.HttpServlet.service(HttpServlet.java:648) at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:843) at javax.servlet.http.HttpServlet.service(HttpServlet.java:729) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:292) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207) at com.tclshop.front.filter.LogTransIdFilter.doFilter(LogTransIdFilter.java:22) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207) at com.tclshop.front.filter.XssFilter.doFilter(XssFilter.java:38) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207) at com.tclshop.front.filter.LoginFilter.filtTclStaff(LoginFilter.java:148) at com.tclshop.front.filter.LoginFilter.doFilter(LoginFilter.java:65) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207) at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207) at org.springframework.web.filter.HttpPutFormContentFilter.doFilterInternal(HttpPutFormContentFilter.java:87) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)



发现代码在执行登录的方法之前已经报了错,并没有打印登录的方法里的日志,日志中有一行是spring的代码,是在这个地方报了空指针org.springframework.web.util.WebUtils.isSameOrigin(WebUtils.java:816)去找下源码:

/** * Check if the request is a same-origin one, based on {@code Origin}, {@code Host}, * {@code Forwarded} and {@code X-Forwarded-Host} headers. * @return {@code true} if the request is a same-origin one, {@code false} in case * of cross-origin request. * @since 4.2 */这一段的翻译:根据{@code Origin},{HostCode}, {@code Forwarded} and {@code X-Forwarded-Host},检查请求是否是同一个请求返回值:{@code true}如果请求是一个同源的请求,返回true,{@code false}在发生跨域请求的情况下,返回false。这个是spring对于跨域的处理报空指针的地方:actualUrl 或者 originUrl
在nginx里加上host配置项,解决问题:加上proxy_set_header  Host  $host; 和 proxy_pass_request_header on;解决问题

 

总结来说,一是自己对spring源码不熟,二是对于nginx的配置不熟。还要多加油啊 文章来源: 记一次上线出现的问题-----org.springframework.web.util.WebUtils.isSameOrigin(WebUtils.java:816)的解决方法(nginx配置问题)

人吐槽 人点赞

猜你喜欢

发表评论

用户名: 密码:
验证码: 匿名发表

你可以使用这些语言

查看评论:记一次上线出现的问题-----org.springframework.web.util.WebUtils.isSameOrigin(WebUtils.java:816)的解决方法(nginx配置问题)