Dear all,
I have an enterprise project with a swing client (deployed to glassfish, runned using jws) and an ejb module.
I want to use CDI for ejb session bean calls, this means use a class member with @EJB annotation, not the lookup method. But I have a problem, that this is working only in the class with main method. In every other class is the member always null. I think, I need to say, that this class is CDI managed, but at this time, I don't know how. I tried to add annotations like @Named,..., but this doesn't work. Can anybody help me?
My env: Java 1.6.24, Glassfish 3.1 b43, Netbeans 7 RC2, Windows 7
Code example (client):
public class Main{ @EJB private static SessionBeanRemote sessionBean; public static void main(String args[]) { sessionBean.test(); // works } } public class NewClass { @EJB private static SessionBeanRemote sessionBean; public static String test(){ return sessionBean.test(); // nullpointerexception } }
Thank you
Michal
If you are invoking it using the new constructor, then you are bypassing the weld proxies. Are you injecting a reference to NewClass in your code?