Hello,
I would like to create a Java EE Module that would be accessible by multiple processes via CDI. The shared module would contain some beans that would handle things like mailing, integration with other systems pdf generation etc. Please see the diagram for hopefully better explanation.
I would like to be able to access this shared module from any process which has the dependency included. I would like to access it preferably the same way as any other bean by the cdi both by the expression eg. ${MyBen.method()} or using @Inject from the Java part of the app.
I think an easy solution is to use cdi producer methods.
You can write a producer method for every service in the shared module. (I’m guessing the shared services module, process 1 and process 2 are different ear files within the application server)
Then you can bundle all producer methods in a jar which is referenced from process 1 and process 2. (Don’t forget the beans.xml in that jar)
Hello Patst,
I tried to go the way you described.I created two things.
First is a shared interface jar.
Which has an interface ITestBean with annotation @Local
and an Imports class which has the producess method:
public class Imports {
@Produces
@EJB(lookup = "java:global/Process-utils-ejb/TestBean")
private ITestBean testBean;
private Imports() {
}
}
And second is “Module” itself which contains the bean:
@Named(value = "TestBean")
@Singleton
public class TestBean implements ITestBean{
public void test(){
System.out.println("Test bean method");
}
}
But the problem is the produces annotaition throws following exception:
Can not set cz.klajmajk.process.utils.shared.interfaces.ITestBean
field cz.klajmajk.process.utils.shared.Imports.testBean
to cz.klajmajk.process.utils.shared.interfaces.ITestBean$$$view3