经过一段时间的研究和尝试,我仍然无法在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 */ );
}发布于 2012-06-12 13:44:43
Spring: RESTful controllers and error handling帮了我,我的问题是缺少这个:
@Component
public class AnnotatedExceptionResolver extends AnnotationMethodHandlerExceptionResolver{
public AnnotatedExceptionResolver() {
setOrder(HIGHEST_PRECEDENCE);
}
}https://stackoverflow.com/questions/10786895
复制相似问题