首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >@ExceptionHandler未被调用

@ExceptionHandler未被调用
EN

Stack Overflow用户
提问于 2012-05-28 23:15:46
回答 1查看 2.3K关注 0票数 3

经过一段时间的研究和尝试,我仍然无法在jUnit集成测试中调用@ExceptionHandler。请帮我解释一下为什么?

代码语言:javascript
复制
@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;
}

代码语言:javascript
复制
@ExceptionHandler(Throwable.class)
public ModelAndView handleUnmarshallingExceptions(Throwable th)
{
// never executes anything in here
return new ModelAndView( /*some parameters */ );
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-06-12 13:44:43

Spring: RESTful controllers and error handling帮了我,我的问题是缺少这个:

代码语言:javascript
复制
@Component
public class AnnotatedExceptionResolver extends AnnotationMethodHandlerExceptionResolver{
  public AnnotatedExceptionResolver() {
    setOrder(HIGHEST_PRECEDENCE);
  }
}
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10786895

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档