我在我的Spring MVC应用程序中添加了以下全局异常定义并获得了以下异常,但我不知道有什么问题我认为我的Spring安全问题但是我不确定任何人可以帮助我吗?
全局异常定义
<!-- 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 -->
当此操作发生任何异常时,我收到异常&#34; org.springframework.web.HttpRequestMethodNotSupportedException:请求方法&#39; GET&#39;不支持&#34;
@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.AntPathRequestMatcher - 检查请求的匹配:&#39; / adduser&#39 ;;反对&#39; / 管理员&#39; DEBUG org.springframework.security.web.util.matcher.AntPathRequestMatcher - 检查请求的匹配:&#39; / adduser&#39 ;;反对&#39; / 用户&#39; DEBUG org.springframework.security.web.access.intercept.FilterSecurityInterceptor - 安全对象:FilterInvocation:URL:/ addUser;属性:[hasRole(&#39; ROLE_ADMIN&#39;)] DEBUG org.springframework.security.web.access.intercept.FilterSecurityInterceptor - 以前经过身份验证:org.springframework.security.authentication.UsernamePasswordAuthenticationToken@bad860a5:校长:org.springframework.security.core.userdetails.User@586034f:用户名:admin;密码保护];启用:true; AccountNonExpired:true; credentialsNonExpired:true; AccountNonLocked:true;授权机构:ROLE_ADMIN;证书:[保护];认证:真实;详细信息:org.springframework.security.web.authentication.WebAuthenticationDetails@fffdaa08:RemoteIpAddress:127.0.0.1; SessionId:52613DC126F07FDCFA50EC1B2841159F;授权机构:ROLE_ADMIN DEBUG org.springframework.security.access.vote.AffirmativeBased - Voter:org.springframework.security.web.access.expression.WebExpressionVoter@4577357d,返回:1 DEBUG org.springframework.security.web.access.intercept.FilterSecurityInterceptor - 授权成功 DEBUG org.springframework.security.web.access.intercept.FilterSecurityInterceptor - RunAsManager没有更改Authentication对象 DEBUG org.springframework.security.web.FilterChainProxy - / addUser到达了额外的过滤器链的末尾;继续与原始链 DEBUG org.springframework.web.servlet.DispatcherServlet - 名称为&#39; mvc-dispatcher&#39;的DispatcherServlet处理[/ Ushers / addUser]的GET请求 DEBUG org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - 查找path / addUser的处理程序方法 EBUG org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver - 解析来自handler [null]的异常:org.springframework.web.HttpRequestMethodNotSupportedException:请求方法&#39; GET&#39;不支持 DEBUG org.springframework.web.servlet.mvc.annotation.ResponseStatusExceptionResolver - 解析来自handler [null]的异常:org.springframework.web.HttpRequestMethodNotSupportedException:请求方法&#39; GET&#39;不支持 DEBUG org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver - 解析来自handler [null]的异常:org.springframework.web.HttpRequestMethodNotSupportedException:请求方法&#39; GET&#39;不支持 WARN org.springframework.web.servlet.PageNotFound - 请求方法&#39; GET&#39;不支持 DEBUG org.springframework.web.servlet.DispatcherServlet - Null ModelAndView返回DispatcherServlet,名称为&#39; mvc-dispatcher&#39 ;:假设HandlerAdapter已完成请求处理 DEBUG org.springframework.web.servlet.DispatcherServlet - 已成功完成请求 DEBUG org.springframework.security.web.access.ExceptionTranslationFilter - 正常处理链 DEBUG org.springframework.security.web.context.SecurityContextPersistenceFilter - SecurityContextHolder现已清除,请求处理完成
答案 0 :(得分: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";
}