How to register a custom exception mapper in Mule + Jersey + Spring?
I built a exception mapper using JAX-RS ExceptionMapper:
@Provider
public class MyCustomExceptionMapper implements ExceptionMapper<MyException>开发者_高级运维;{...}
It is unclear to me is how to register it so that when MyException is thrown, the mapper is called automatically. The environment I am using is Mule + Jersey + Spring.
If you're using 3.1.2-SNAPSHOT+ or 3.2-SNAPSHOT+ you can do this:
<jersey:resources>
<component class="org.mule.module.jersey.HelloWorldResource"/>
<jersey:exception-mapper class="org.mule.module.jersey.exception.HelloWorldExceptionMapper" />
</jersey:resources>
This response says to use @Repository with Spring
JAX-RS Custom ExceptionMapper not intercept RuntimeException
Mule 3.4.0 includes the support:
https://www.mulesoft.org/jira/browse/MULE-5458
<sub-flow name="RestServiceFlow">
<jersey:resources>
<component class="org.example.AResource"/>
<component class="org.example.BResource"/>
<jersey:exception-mapper class="org.example.AExceptionHandler" />
<jersey:exception-mapper class="org.example.BExceptionHandler" />
</jersey:resources>
</sub-flow>
The classes are annotated with the @Provider annotation as described in the question.
精彩评论