How do I ignore a specific exception from the UI?
How can I let the current Spring application ignore a specific exception class (like NoUIException or OptimisticLockingException
) in the UI, but not affect the logging? I know I org.springframework.web.servlet.handler.SimpleMappingExceptionResolver
can display a specific UI request exception, but don't know how to avoid it in the UI.
UPDATE
I am researching Spring website and come up with the following solution, I tried it but it doesn't work.
@ControllerAdvice
public class ExceptionControllerAdvice {
@ResponseStatus(value = HttpStatus.CONFLICT)
@ExceptionHandler(org.apache.openjpa.persistence.OptimisticLockException.class)
public void optimisticLockExceptionHandler() {
// do nothing, just ignore the exception
logger.info("yeah...no exception I hope !!!");
}
}
UPDATE2
I'm not sure if this is relevant, but I have register SimpleMappingExceptionResolver
in the context of the mvc config
<bean class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver" p:defaultErrorView="uncaughtException">
<property name="exceptionMappings">
<props>
<prop key=".DataAccessException">dataAccessFailure</prop>
<prop key=".AccessDeniedException">accessDenied</prop>
</props>
</property>
</bean>
Is there a way to SimpleMappingExceptionResolver
have a conflict with controller advisor
?
source to share
The exception handler is called by a HandlerExceptionResolver named ExceptionHandlerExceptionResolver.
Make sure you have configured component scanning correctly; the package containing your tips should be scanned. Don't forget to include annotations.
In Spring XML:
<context:component-scan base-package="com.foo.bar" />
<mvc:annotation-driven>
Spring Boot uses @ComponentScan ( http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/context/annotation/ComponentScan.html ). Then you need to extend the WebMvcConfigurerAdapter class and specify your permissions. These converters are placed in HandlerExceptionResolverComposite. The first resolver returning a non-empty model and viewing the payoffs.
source to share