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

?

+3


source to share


2 answers


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.

0


source


If you don't want to display an error page for a specific exception, then catch that exception with a catch block and don't throw any application specific exception.



0


source







All Articles