我写了一个JCA resource adapter before .
但是,现在我发现自己不得不写一个来访问 BootstrapContext
及其相关联的 WorkManager
,而且没有其他原因。
如果我正确阅读规范——这是我的问题——看起来如果我希望有人能够以符合规范的方式使用我的资源适配器,我仍然需要实现 ManagedConnectionFactory
,因为看起来只有 ManagedConnectionFactory
实现提供的用户连接工厂才有资格通过 @Resource
注释进行注入(inject)。
继续,再读一遍;我会等。 :-)
在一个完美的世界中,我想编写我的 ResourceAdapter
实现,用 @Connector
注释它,指定所有 @ConfigProperty
位,将其打包成一个.rar
文件,然后就完成了。
但是,在我看来,规范实际上要求消费者(在我的例子中是无状态 EJB)和资源适配器模块之间的所有通信都应该通过用户连接工厂来完成。
例如,第 6.10.1 节说:
A resource adapter must provide implementations of the following interfaces:
- javax.resource.spi.ManagedConnectionFactory
- javax.resource.spi.ManagedConnection
- javax.resource.spi.ManagedConnectionMetaData
但第 18 节——关于注释的部分——似乎并没有以任何有意义的方式强制执行这一点。
真的是这样吗?我想肯定是这样,但我很想听听那些组装了 1.6 资源适配器的人的意见。
最佳答案
“本节概述了连接管理契约(Contract)的要求。”
Is it legal, using only JCA 1.6 annotations, to simply define a ResourceAdapter implementation with--basically--nothing else in the module?
是的。这很好。
The specification indicates in section 19.2 that an outbound resource adapter (which this would be) must {handwave handwave} make use of the connection management,
transaction management and security management contracts. In all three cases, I just want to indicate--preferably by omitting annotations and/or code--that I don't suppo'r't any of them
如果您不需要出站通信功能,则不必定义它们(连接工厂、托管连接工厂等)
Is it sufficient to simply build a POJO that implements ResourceAdapter, annotate it with @Connector, and go from there?
是的。
Can I then inject such a POJO into my EJB using the @Resource annotation?
我不认为可以使用@Resource 注解注入(inject)“ResourceAdapter”Java Bean。每当资源适配器部署/启用/服务器启动时,
GlassFish 将引导资源适配器。
关于java - JCA 1.6 ResourceAdapter 是否需要 ManagedConnectionFactory?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4199146/