在一个项目中异常处理是很重要的,springmvc就提供的这样的异常处理机制:ControllerAdvice,而且非常好用。因为最近项目在用,所以也看了蛮多
的文章,试了下都没成功,就在山穷水尽之时,看到了一句话当:"加上ControllerAdvice注解,注意这个类是在controller包下面,因为spring需要扫描到",这样就ok啦。
这样写之后也不需要下面的配置:
<context:component-scan base-package="com.ehu.action" use-default-filters="false">
<context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
<context:include-filter type="annotation" expression="org.springframework.web.bind.annotation.ControllerAdvice"/> </context:component-scan>
第一次写,写的有点烂!