开发者

How to register a custom exception mapper in Mule + Jersey + Spring?

开发者 https://www.devze.com 2023-02-18 04:38 出处:网络
I built a exception mapper using JAX-RS ExceptionMapper: @Provider public class MyCustomExceptionMapper implements ExceptionMapper<MyException>开发者_高级运维;{...}

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号