是否可以将 CamelContext 的 ShutdownStrategy 外包到中央 OSGi 包中?

Is it possible to outhouse ShutdownStrategy for CamelContext into a central OSGi bundle?

我正在尝试将我的 OSGi 捆绑包的中央 bean 外包到一个中央捆绑包中,该中央捆绑包将它们作为服务提供。这适用于 ErrorHanders 和处理器,但不适用于 ShutdownStrategy and RedeliveryPolicy。我收到的错误消息是

org.osgi.service.blueprint.container.ComponentDefinitionException: A class org.apache.camel.processor.RedeliveryPolicy was found in the interfaces list, but class proxying is not allowed by default. The ext:proxy-method='classes' attribute needs to be added to this service reference.

我可以尝试按照说明添加 ext:proxy-method,但首先我想了解这里的线索。也许集中战略和政策不是一个好主意?

[编辑] 这里的错误是在服务中使用 class 而不是 interface。所以 interface="org.apache.camel.spi.ShutdownStrategy" 应该是这里的正确接口(对于 ShutdownStrategy)。带有我的骆驼路线的捆绑包引用了此服务:

<reference
    id="shutdownStrategy"
    interface="org.apache.camel.spi.ShutdownStrategy"
    component-name="shutdownStrategy" />

但现在我得到以下错误:

java.lang.IllegalArgumentException: CamelContext must be specified

[编辑] 我想将这个问题限制在 ShutdownStrategy,因为 RedeliveryPolicy 当我在中央包内的 ErrorHandlers 中引用它时工作正常。

那么是否也可以将 ShutdownStrategy 外置?也许不是,因为 it needs a CamelContext.

When using Spring XML you then just define a spring bean which implements the org.apache.camel.spi.ShutdownStrategy and Camel will look it up at startup and use it instead of its default.

我在 Camel documentation

中找到了答案

You can implement your own strategy to control the shutdown by implementing the org.apache.camel.spi.ShutdownStrategy and the set it on the CamelContext using the setShutdownStrategy method.

When using Spring XML you then just define a spring bean which implements the org.apache.camel.spi.ShutdownStrategy and Camel will look it up at startup and use it instead of its default.

因此,如果您有自己的 ShutdownStrategy 实现,则可以将其用作 bean。

<bean id="shutdownStrategy"
    class="org.apache.camel.spi.ShutdownStrategy">
</bean>