Announcement Announcement Module
Collapse
No announcement yet.
SimpleMappingExceptionResolver BUG? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • SimpleMappingExceptionResolver BUG?

    Do I missunderstand the usage of SimpleMappingExceptionResolver?
    <bean id="exceptionResolver" class="org.springframework.web.servlet.handler.Sim pleMappingExceptionResolver">
    <property name="exceptionMappings">
    <props>
    <prop key="cn.liujiangsheng.service.Exception_Login">exc eption_login</prop>
    <prop key="java.lang.Exception">exception</prop>
    </props>
    </property>
    </bean>
    If Exception_Login is throwed out, exception_login view will be displayed. And other exceptions are throwed out, exception view will be showed. But, I find that when Exception_Login was throwed out, it leads to exception view.
    I check out source file org.springframework.web.servlet.handler.SimpleMapp ingExceptionResolver, and have a question about these lines.

    public ModelAndView resolveException(
    HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {
    ...
    // Check for specific exception mappings.
    if (this.exceptionMappings != null) {
    int deepest = Integer.MAX_VALUE;
    for (Enumeration names = this.exceptionMappings.propertyNames(); names.hasMoreElements() {
    String exceptionMapping = (String) names.nextElement();
    int depth = getDepth(exceptionMapping, ex);
    if (depth >= 0 && depth < deepest) {
    deepest = depth;
    viewName = this.exceptionMappings.getProperty(exceptionMappin g);
    ////////////////////////////// look here please:
    ///////////////////////////// If we found the match exception, should we have a break here?
    ///////////////////////////// Do I missunderstand the idea of the spring error handle architecture?
    }
    }
    }
    ...
    }

    Anyone should help me please.
    Thanks in advance.

    ifun

  • #2
    viewName = this.exceptionMappings.getProperty(exceptionMappin g);
    ////////////////////////////// look here please:
    ///////////////////////////// If we found the match exception, should we have a break here?
    ///////////////////////////// Do I missunderstand the idea of the spring error handle architecture?
    well, SimpleMappingExceptionResolver looks for the nearest exception. If we have two Exceptions E2 (view2) that extends E1 (view1) and your controller throws E3 that extends E2 (E3 -> E2 -> E1). SimpleMappingExceptionResolver should return view2 as E3 is closer to E2 than E1.
    HTH

    Comment


    • #3
      Originally posted by irbouho
      viewName = this.exceptionMappings.getProperty(exceptionMappin g);
      ////////////////////////////// look here please:
      ///////////////////////////// If we found the match exception, should we have a break here?
      ///////////////////////////// Do I missunderstand the idea of the spring error handle architecture?
      well, SimpleMappingExceptionResolver looks for the nearest exception. If we have two Exceptions E2 (view2) that extends E1 (view1) and your controller throws E3 that extends E2 (E3 -> E2 -> E1). SimpleMappingExceptionResolver should return view2 as E3 is closer to E2 than E1.
      HTH
      I see.
      Magic was here:
      deepest = depth;

      Thank you and thank to Rod for he bring us so beatiful framework.
      ifun

      Comment

      Working...
      X