3

しばらく調べてさまざまなことを試した後でも、jUnit統合テストで@ExceptionHandlerを呼び出せません。理由を理解するのを手伝ってください。

@RequestMapping(value = "/someURL", method = RequestMethod.POST)
public ModelAndView batchUpload(@RequestBody final String xml, @RequestParam boolean replaceAll)
    throws IOException, URISyntaxException, SAXException, ParserConfigurationException, InvocationTargetException, IllegalAccessException, UnmarshallingFailureException
{
StreamSource source = new StreamSource(new StringReader(xml));
DomainClass xmlDomainClass;

try
{
    xmlDomainClass = (DomainClass) castorMarshaller.unmarshal(source);
}
catch (UnmarshallingFailureException me)
{
    // some logging. this gets executed
    throw me;
}

@ExceptionHandler(Throwable.class)
public ModelAndView handleUnmarshallingExceptions(Throwable th)
{
// never executes anything in here
return new ModelAndView( /*some parameters */ );
}
4

1 に答える 1

4

Spring:RESTfulコントローラーとエラー処理が役に立ちました。私の問題はこれがないことでした:

@Component
public class AnnotatedExceptionResolver extends AnnotationMethodHandlerExceptionResolver{
  public AnnotatedExceptionResolver() {
    setOrder(HIGHEST_PRECEDENCE);
  }
}
于 2012-06-12T05:44:43.413 に答える