开发者

Where can I place eligible candidates for CDI in a Glassfish v3 deployment?

开发者 https://www.devze.com 2023-03-28 14:48 出处:网络
I have code in one jar (a.jar) which contains an @Inject X x. I want to satisfy the injection with an implementation in another jar (b.jar, being a valid bean archive etc.).

I have code in one jar (a.jar) which contains an @Inject X x.

I want to satisfy the injection with an implementation in another jar (b.jar, being a valid bean archive etc.).

To my understanding, I cannot deploy a.jar and b.jar in separate WAR standalone archives as these are independent CDI开发者_运维问答-wise. I may be able to put b.jar in the lib folder that Glassfish provides to all deployments (but is this "pure Java 6 EE" and this mean I cannot deploy in the same way as a war or an ear?). I may be able to provide b.jar in an EAR placed in lib along with a.war or a.jar but I am unfamiliar with this.

My question is which options do I have for deploying a.jar and b.jar so that Glassfish (currently 3.0.1 but I will consider 3.1.1 if it works better) will correctly resolve this dependency? I am looking for an exhaustive list.

(EDIT: I'd prefer a solution where b.jar can be deployed independently of a.jar)


I think a good option is putting a.jar andb.jar in the lib folder of your project. Please tell if you think it has drawbacks.


I would see if I could turn the relevant objects in b.jar into EJBs, effectively turning b.jar into a EJB 3 'service'.

Then, in a.jar (and any other code that needs the service), I would use a CDI Producer method to perform JNDI lookup, allowing me to @Inject the EJB just like any local resource.

Alternatively, if you can also turn a.jar into an EJB 3 'service' then EJB's from b.jar can be injected directly by the container (using Java EE @EJB or @Resource injection) into a.jar's EJBs.

0

精彩评论

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