注册后发布方法 - java.lang.IllegalArgumentException

时间:2017-08-13 22:53:21

标签: java mongodb spring-mvc spring-security spring-data

当我注册时,我得到以下错误,但用户已注册,我看到在MongoDB终端注册的条目。

HTTP Status 500 - Request processing failed; nested exception is java.lang.IllegalArgumentException

栈跟踪

SEVERE: Servlet.service() for servlet [LivePrice] in context with path [] threw exception [Request processing failed; nested exception is java.lang.IllegalArgumentException] with root cause
java.lang.IllegalArgumentException
    at org.apache.catalina.connector.Response.normalize(Response.java:1823)
    at org.apache.catalina.connector.Response.toAbsolute(Response.java:1743)
    at org.apache.catalina.connector.Response.encodeRedirectURL(Response.java:1208)
    at org.apache.catalina.connector.ResponseFacade.encodeRedirectURL(ResponseFacade.java:417)
    at org.springframework.web.servlet.view.RedirectView.sendRedirect(RedirectView.java:610)
    at org.springframework.web.servlet.view.RedirectView.renderMergedOutputModel(RedirectView.java:320)
    at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:303)
    at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1286)
    at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1041)
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:984)
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:901)
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
    at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:872)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:650)
    at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:218)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:110)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:506)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:962)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:445)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1115)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:637)
    at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2549)
    at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2538)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Thread.java:745)

控制器

@RequestMapping(value="/register", method= RequestMethod.GET)
public String register(ModelMap modelMap){
    modelMap.put("user", new User());
    return "account/register";
}


@RequestMapping(value="/register", method= RequestMethod.POST)
public String register(@ModelAttribute("user") User user){
    BCryptPasswordEncoder bCryptPasswordEncoder = new BCryptPasswordEncoder();
    user.setPassword(bCryptPasswordEncoder.encode(user.getPassword()));
    userService.register(user);

    return "redirect:../login";
}

在UserDAOImpl

@Override
public void register(User user) {

    mongoTemplate.insert(user);
}

UserServiceImpl

@Override
public void register(User user) {
     userDao.register(user);
}

1 个答案:

答案 0 :(得分:0)

替换

return "redirect:../login";

return "redirect:/login";

的工作。