【发布时间】:2016-11-15 12:49:54
【问题描述】:
我的 Spring Web 模型-视图-控制器 (MVC) 框架中有这个类。 Spring Web 模型-视图-控制器(MVC)框架的版本是 3.2.8
我有这个控制器
public class WelcomeController extends ViewController {
@Autowired
private UserService userService;
@Autowired
private SessionHelper sessionHelper;
public ModelAndView handleRequest(final HttpServletRequest request, HttpServletResponse response) throws Exception {
sessionHelper.invalidate(request, new String[] { SubmitController.CONFIRMATION_INFO,
SubmitController.CONFIRMATION_INFO2,
SubmitController.CONFIRMATION_INFO3,
"changePrdStatus" });
HttpSession session = request.getSession();
DetailedUser ecasUser = (DetailedUser)request.getUserPrincipal();
User usr = userService.getUserFromLDAP(ecasUser);
..
}
抛出这个异常
com.tdk.iop.domain.security.ApplicationException: more than 1 user with the same email
at com.tdk.iop.dao.impl.UserDaoImpl.findByEmail(UserDaoImpl.java:195)
at com.tdk.iop.services.impl.ServiceSupport.getEcasUser(ServiceSupport.java:46)
at com.tdk.iop.services.impl.UserServiceImpl.getUserFromEcas(UserServiceImpl.java:37)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
at org.springframework.aop.framework.adapter.MethodBeforeAdviceInterceptor.invoke(MethodBeforeAdviceInterceptor.java:51)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:96)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:260)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:94)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:91)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
at com.sun.proxy.$Proxy596.getUserFromEcas(Unknown Source)
at com.tdk.iop.controller.welcome.WelcomeController.handleRequest(WelcomeController.java:64)
at org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:48)
web.xml 上的这个
<error-page>
<exception-type>com.tdk.iop.domain.security.ApplicationException</exception-type>
<location>/errors/error500.do</location>
</error-page>
但是申请没有到达Error500Controller
【问题讨论】:
-
我认为您的问题与方法签名有关。您将 spring-mvc 配置为处理 ApplicationException,但您的方法会抛出更通用的 Exception。或许你必须完善 spring-mvc 配置。
-
你必须在你的 spring 配置 xml 中添加 SimpleMappingExceptionHandler bean。检查此链接mkyong.com/spring-mvc/spring-mvc-exception-handling-example
标签: java spring spring-mvc