2014-12-13 71 views
0

我在我的Spring MVC應用程序中添加了全局異常的定義,並且得到了下面的異常但我不知道什麼是錯誤我認爲我的Spring安全性問題但我不是確定任何人都可以幫助我?在Spring MVC中的全局異常defen不起作用

全局異常的定義

<!-- global exception mapping --> 
<bean class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver"> 
    <property name="exceptionMappings"> 
    <map> 
     <entry key="DataAccessException" value="error" /> 
    </map> 
</property> 
<property name="defaultErrorView" value="error"/> 
</bean> 
<!-- end global exception mapping --> 

當任何異常發生在這個動作我得到一個異常 「org.springframework.web.HttpRequestMethodNotSupportedException:請求方法 'GET' 不支持」

@RequestMapping(value ="/addUser", method = RequestMethod.POST) 
public String addUser(@Valid User user, BindingResult result, Model model, @RequestParam("userRole") String role) throws Exception { 
    if(result.hasErrors()) { 
     return "register"; 
    } 
    String hashPassword = new PasswordHashProcessor().getHashPassword(user.getPassword()); 
    user.setPassword(hashPassword); 
    daoService.addUser(user, role); 
    List<UserRole> users = daoService.getNotAdminUsers(); 
    model.addAttribute("users", users); 
    return "users"; 
} 

的顯示日誌如下

DEBUG org.springframework.security.web.util.matcher.A ntPathRequestMatcher - 檢查請求匹配:'/ adduser';反對'/ admin' DEBUG org.springframework.security.web.util.matcher.AntPathRequestMatcher - 檢查請求匹配:'/ adduser';反對'/ 用戶' DEBUG org.springframework.security.web.access.intercept.FilterSecurityInterceptor - 安全對象:FilterInvocation:URL:/ addUser;屬性:[hasRole('ROLE_ADMIN')] DEBUG org.springframework.security.web.access.intercept.FilterSecurityInterceptor - 先前已驗證:org.springframew[email protected]bad860a5:Principal:org.springframework.security.core .userdetails.User @ 586034f:用戶名:admin;密碼保護];啓用:true; AccountNonExpired:true; credentialsNonExpired:true; AccountNonLocked:true;授予權限:ROLE_ADMIN;證書:[PROTECTED];已驗證:true;詳細信息:org.sprin[email protected]fffdaa08:RemoteIpAddress:127.0.0.1; SessionId:52613DC126F07FDCFA50EC1B2841159F;授予權限:ROLE_ADMIN DEBUG org.springframework.security.access.vote.AffirmativeBased - 選票:org.sp[email protected]4577357d,返回:1 DEBUG org.springframework.security.web.access .intercept.FilterSecurityInterceptor - 授權成功 DEBUG org.springframework.security.web.access.intercept.FilterSecurityInterceptor - RunAsManager未更改身份驗證對象 DEBUG org.springframework.security.web.FilterChainProxy -/addUser已到達其他過濾器鏈的末尾;繼續處理原始鏈 DEBUG org.springframework.web.servlet.DispatcherServlet - 名爲'mvc-dispatcher'的DispatcherServlet處理[/ Ushers/addUser]的GET請求 DEBUG org.springframework.web.servlet.mvc.method.annotation。 RequestMappingHandlerMapping - 查找路徑/ addUser的處理程序方法 EBUG org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver - 解決處理程序異常[null]:org.springframework.web.HttpRequestMethodNotSupportedException:請求方法'GET'not支持 DEBUG org.springframework.web.servlet.mvc.annotation.ResponseStatusExceptionResolver - 解決處理函數[null]中的異常:org.springframework.web.HttpRequestMethodNotSupportedException:不支持請求方法'GET' DEBUG org.springframework.web.servlet。 mvc.support.DefaultHandler ExceptionResolver - 解決處理異常[null]:org.springframework.web.HttpRequestMethodNotSupportedException:不支持請求方法'GET' WARN org.springframework.web.servlet.PageNotFound - 不支持請求方法'GET' DEBUG org.springframework。 web.servlet.DispatcherServlet - 空ModelAndView返回到名爲'mvc-dispatcher'的DispatcherServlet:假設HandlerAdapter完成請求處理 DEBUG org.springframework.web.servlet.DispatcherServlet - 成功完成請求 DEBUG org.springframework.security.web.access 。的ExceptionTranslationFilter - 鏈處理通常 DEBUG org.springframework.security.web.context.SecurityContextPersistenceFilter - SecurityContextHolder中現在清零,作爲完成

回答

0

此更新解決的問題請求處理,

@RequestMapping(value ="/addUser", method = RequestMethod.POST) 
public String addUser(@ModelAttribute("user") @Valid User user, BindingResult result) { 

    if(result.hasErrors()) { 
     return "register"; 
    } 
    String hashPassword = new PasswordHashProcessor().getHashPassword(user.getPassword()); 
    user.setPassword(hashPassword); 
    daoService.addUser(user); 
    return "redirect:/getUsers"; 
}