必须在我用XML定义的camel路由中抛出异常.发现throwException声明可从Camel 2.3获得,如下所示:
<throwException ref="forced"></throwException>
Run Code Online (Sandbox Code Playgroud)
但是,我不知道如何定义forced要抛出的异常类.由于可以使用不同的异常消息多次抛出相同的异常 - 最好知道是否throwException具有其他形式的定义,以便就地定义异常类和异常消息.
Cla*_*sen 18
ref只是对a的引用,所以你可以这样做
<bean id="forced" class="java.lang.IllegalArgumentException">
<constructor-arg index="0" value="This is forced"/>
</bean>
<camelContext ...>
...
</camelContext>
Run Code Online (Sandbox Code Playgroud)
从版本2.16.0开始,有更优雅的方式,可选的异常消息:
<route>
<throwException exceptionType="java.lang.IllegalArgumentException" message="illegal argument found"/>
</route>
Run Code Online (Sandbox Code Playgroud)