@EJB injection

Hi,
I've seen this asked before, but there was never enough information, so I'm going to ask this again.
I am trying a simple test with WebLogic 10.0 MP1.
I have created an EAR file with 3 modules inside:
1. A JAR file containing a stateless EJB.
2. A WAR file containing a POJO webservice (using the @WebService annotation).
3. A WAR file containing a servlet.
The EJB code:
public interface IHelloWorld
     public void hello();
import javax.ejb.Local;
import javax.ejb.Remote;
import javax.ejb.Stateless;
@Stateless
@Local( IHelloWorld.class )
@Remote( IHelloWorld.class )
public class HelloWorld implements IHelloWorld
     public void hello()
          System.out.println( "Hello EJB3!" );
The EJB seems to deploy fine, and I can see it in the JNDI tree, and also in the console.
Also, I can reach the web-service and the servlet just fine.
Now, I've added the following member to both the servlet and the web service:
     @EJB
     private IHelloWorld helloWorld;
And in the activated method (service in the servlet, and the method on the web-service) I've added the following code:
          if ( helloWorld != null )
               helloWorld.hello();
          else
               System.out.println( "helloWorld is null. Bah." );
I'm always getting that helloWorld is null, meaning the injection was not performed by the server.
I am not using any deployment descriptors aside from application.xml in the EAR file, and the generated files in the created WAR file for the web-service (used jwsc ant to create the web-service).
Any ideas?
-- Nimrod

Well, I solved it myself.
Apparently, in order for EJB injection to work in a servlet / webservice, WebLogic server needs to know that the web application is using version 2.5 of the servlet API. To do this, replace your web-app directive in your web.xml with this:
<web-app id="test" version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
Now EJB injection works.

Similar Messages

  • Javax.ejb.Inject not found

    I'm working with jdeveloper 10.1.3 in S.O. XP
    build a proyect template JSP,EJB3,TOPLINK
    import javax.ejb.Inject;
    Error: Inject not found
    Tanks

    Add EJB 3.0 Library to project libraries.

  • EJB Injection in Seperated Managed Bean

    Hi All,
    I have a JSF project consisting of a number of different WARs, containing the Web logic, and a bunch of different JARs, containing the application logic; which are deployed together in a single EAR file. Thus far this approach has worked excellently, but I've now run into a problem. I would like to have a managed session-scoped bean which should be available to all the WARs' classes so that they can store cross-application data in it (for example the user's name and other details). I can do this by packaging that session-scoped bean, along with its faces-config.xml, into a JAR which is deployed through the EAR. This works fine, but EJB Injection in that session-scoped bean doesn't work - my bean interface instance always contains null.
    Is there someway that I can have EJB Injection in this managed session-scoped bean contained in a JAR? I realize that EJB Injection requires a container, but seeing as it is a managed bean, even though it isn't inside a WAR, I thought this should work fine?
    Thank you,
    Ristretto

    We tried almost every permutation and combination, but it did not work without that dummy servlet.
    Then we had to look for a cleaner solution and we found one.
    We are now using spring injection, to get the EJB injection in our session managed bean. This way the code is extensible and cleaner.
    In future if you want something else(other than ejb lets say a web service), you will just change the Spring config file and it would't break anything.
    Edited by: desu on Mar 14, 2008 4:20 AM

  • @EJB injection fails in 11gR1?

    Hi !
    I can't get the @EJB injection to work on 11g R1. Is there any known issues?
    I tried this example : http://glassfish.java.net/javaee5/ejb/examples/Sless.html
    but the Weblogic server only gives NullpointerExeption.
    Is there any additional code that need to be added ?
    Regards, reZer

    Hi,
    I am having exactly the same problem with my application.
    Have your resolved this and how. I think may be the EJB jar
    is not being deployed. The Java naming directory interface(JNDI)
    to which you used the initialiseContext to insert the works for me too.
    But the @EJB injection does not work. You provided the JNDI name
    for Accountcontroller and that works but it won't work with injection.
    You only provide the client with the JNDI of the session bean only
    if you are using a stand alone client. But if you are running the client
    as an application client, you need to use the @EJB injection.
    I am also stack looking for solution.
    Thanks
    eve

  • EJB Injection into JSR286 Portlet

    I'm currently facing an issue accessing an Stateless EJB from my JSR286 Weblogic 10.3.2 Portal Server. I have 2 ears: 1) PreferencesPortalEAR and 2)PreferencesEJBEar
    PreferencesPortalEAR - contains the web module with jsr286 portlet and the ejb client jar
    PreferencesEJBEar - contains the j2ee module with the ejb and ejb client jar
    When I attempt to access the EJB from the portlet doing a JNDI lookup it works fine but when I try to use DI to get a reference to the bean I get a NullPointerException.
    Here's the code:
    PreferenceBean EJB:
    * Session Bean implementation class PreferencesBean
    @Stateless(mappedName="ejb/Preference")
    public class PreferenceBean implements PreferenceLocal, PreferenceRemote {
         @Override
         public void createPreference(List<PreferenceEntity> preferences) {
              System.out.println("Created Preference");
         @Override
         public void deletePreference(List<PreferenceEntity> preferences) {
              System.out.println("Deleted Preference");
         @Override
         public List<PreferenceEntity> getPreference(PreferenceType prefType) {
              System.out.println("Get Preference");
              ArrayList<PreferenceEntity> peAL = new ArrayList<PreferenceEntity>();
              for (int i=0;i<10;i++) {
                   PreferenceEntity pe = new PreferenceEntity();
                   pe.setId(i);
                   pe.setCreateDate(new Date());
                   pe.setPreferenceName("prefName" + i);
                   pe.setPreferenceValue("prefValue"+i);
                   pe.setUserName("weblogic"+i);
                   peAL.add(pe);
              return peAL;
         @Override
         public void updatePreference(List<PreferenceEntity> preferences) {
              System.out.println("Update Preference");
    Here's the Portlet EJBPortlet:
    public class EJBPortlet extends GenericPortlet {
         @EJB(mappedName="ejb/Preference")
         private Preference preference;
         public void doView(RenderRequest request, RenderResponse response)
                   throws PortletException, IOException {
              response.setContentType("text/html");
    //          Context ctx = null;
    //          Preference preference = null;
    //          try {
    //               /** not needed when running locally **/
    //               Hashtable<String, String> env = new Hashtable<String, String>();
    //               env.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
    //               env.put(Context.SECURITY_PRINCIPAL,"weblogic");
    //               env.put(Context.SECURITY_CREDENTIALS,"weblogic123");
    //               env.put(Context.PROVIDER_URL,"t3://localhost:7001");
    //               ctx = new InitialContext();
    //               preference = (Preference) ctx.lookup("ejb/Preference#com.mycompany.preferences.PreferenceRemote");
    //          } catch (Exception e) {
    //               e.printStackTrace();
              preference.createPreference(null);
              preference.deletePreference(null);
              ArrayList<PreferenceEntity> peAL = (ArrayList<PreferenceEntity>)preference.getPreference(PreferenceType.CATEGORY);
              for (PreferenceEntity pe : peAL) {
                   response.getWriter().write(pe.toString() + " ") ;
              response.getWriter().write("<p>Hello World!</p>");
    As previously mentioned, using InitialContext and JNDI lookup in the portlet works fine. When that code is commented and I use @EJB, I get a NullPointerException.
    Thanks for your help.

    We tried almost every permutation and combination, but it did not work without that dummy servlet.
    Then we had to look for a cleaner solution and we found one.
    We are now using spring injection, to get the EJB injection in our session managed bean. This way the code is extensible and cleaner.
    In future if you want something else(other than ejb lets say a web service), you will just change the Spring config file and it would't break anything.
    Edited by: desu on Mar 14, 2008 4:20 AM

  • Web Service @EJB injection isn't working

    I'm running WebLogic Server 10.0 MP1
    I have a local interface:
    @Local
    public interface Login {
         boolean loginUser( String username, String password );
    }And an implementation:
    @Stateless
    @Local
    public class LoginBean implements Login {
         public boolean loginUser(String username, String password) {
              if (username != null && password != null && username.equals("test")
                        && password.equals("password")) {
                   return true;
              return false;
    }Those are bundled up in service.jar
    I also have a Web Service:
    @Stateless
    @WebService(name = "LoginService", targetNamespace = "http://my.namespace/here")
    @WLHttpTransport(contextPath = "services", serviceUri = "LoginService")
    public class LoginService {
         @EJB(name="bLogin")
         private Login login;
         @WebMethod
         public boolean login(String username, String password) {
              return login.loginUser(username, password);
    }The webservice is bundled into LoginService.war by the jswc ant task.
    LoginService.war and services.jar are together bundled into my .ear file with an appropriate application.xml, and the web console shows both the web service and EJB as being deployed with the EAR.
    When I access the LoginService, I always get a NullPointerException on the return login.loginUser() line (and a println indicates that in fact login is null).
    So WebLogic isn't injecting my bean into the login variable, however there are no warnings or errors on the console.
    I have seen http://forums.bea.com/thread.jspa?threadID=300003881 but that doesn't help, as my web.xml is generated by jswc and I verified that it always sets the version to 2.5 and namespace properly.
    One other interesting tidbit: If I set beanName to something crazy (like "foo") on the @EJB annotation in LoginService, I DO get an error (at deployment time) in the server log saying that the ejb-link for 'foo' wasn't found. So the lookup appears to be happening (though there is nothing about an ejb-link in the web.xml, I expect that it is implicitly happening at deploy time from the @EJB annotation) just not the actual injection.
    Thoughts?

    Since it looks like no one from BEA actually monitors these forums, I'll answer my own question.
    I no longer use the jswc ant task to generate LoginService.war. Now, I just drop my Login web service into its own jar file (apparently it doesn't work if it's in a JAR with other EJBs), say, ws.jar and put that into the EAR with everything else, and it works. Here is my web service now (called LoginImpl)
    @WebService(name = "Login", targetNamespace = MY_NAMESPACE)
    @SOAPBinding(style = Style.DOCUMENT, use = Use.LITERAL, parameterStyle = ParameterStyle.WRAPPED)
    @WLHttpTransport(contextPath = "services", serviceUri = "LoginService")
    @Stateless
    public class LoginImpl {
         @EJB(name = "Login")
         private Login login;
         @WebMethod(operationName="LoginRequest")
         @WebResult(name = "LoginResponse")
         public boolean login(
              @WebParam(name = "Username", targetNamespace = MY_NAMESPACE) String username,
              @WebParam(name = "Password", targetNamespace = MY_NAMESPACE) String password
              return login.loginUser( username, password );
         @WebMethod(operationName="LogoutRequest")
         @WebResult(name="LogoutResponse")
         public void logout( @WebParam(name = "SessionToken", targetNamespace = MY_NAMESPACE) String sessionToken ) {
              login.logoutUser( sessionToken );
    }So in summary:
    * Put @WebService files in their own JAR
    * Don't use jswc
    I also used Sun's JAX-WS reference implementation to generate the *.jaxwx.* files, otherwise WebLogic complains

  • Best practice for @EJB injection in junit test (out-of-container) ?

    Hi all,
    I'd like to run a JUnit test for a Stateless bean A which has another bean B injected via the @EJB annotation. Both beans are pure EJB 3 POJOs.
    The JUnit test should run out-of-container and is not meant to be an EJB client, either.
    What is the easiest/suggested way of getting this injection happening without explicitely having to instantiate the bean B in my test setup ?

    you can deal with EntityBeans without having the Container managed senario , you can obtain instance of EntityManager using the "EntityManagerFactory" and providing the "persistence.xml" file and provide the "provider" (toplink,hibernate ,...), then you can use entities as plain un managed classes

  • Can't get EJB injection to work, Please Help!

    I'm new to EJB 3.0, so I tried the "sample" EJB 3.0 stateless session bean sample from Oracle for JDev. (I'm using JDev 10.1.3.1.0 bld. 3984), very simple stuff:
    package project1;
    import javax.ejb.Remote;
    @Remote
    public interface Hello {
    void sayHello(String inStr);
    and
    package project1;
    import javax.ejb.Stateless;
    @Stateless(name="Hello")
    public class HelloBean implements Hello {
    public HelloBean() {
    public void sayHello(String inStr) {
    System.out.println("Hello " + inStr );
    I can deploy the Bean w/ no problems to the embedded OC4J (in JDev) by just clicking "Run" on it, and I can successfully run the "Client" based on the "Older" implicit JNDI look up as follows:
    package project1;
    import javax.naming.Context;
    import javax.naming.InitialContext;
    import javax.naming.NamingException;
    public class HelloClient {
    public static void main(String [] args) {
    try {
    final Context context = getInitialContext();
    Hello hello = (Hello)context.lookup("Hello");
    Call any of the Remote methods below to access the EJB
    hello.sayHello("John Doe");
    } catch (Exception ex) {
    ex.printStackTrace();
    private static Context getInitialContext() throws NamingException {
    // Get InitialContext for Embedded OC4J
    // The embedded server must be running for lookups to succeed.
    return new InitialContext();
    The above client code works fine, too.
    But when I try to run the following client (It compiles fine):
    package project1;
    import javax.ejb.EJB;
    public class HelloClient {
    @EJB private static Hello hello;
    public static void main(String [] args) {
    try {
    hello.sayHello("John Doe");
    } catch (Exception ex) {
    ex.printStackTrace();
    It DOES NOT work, the @EJB private static Hello hello seem to never get executed, as "hello" is always null and I get a null pointer exception on (hello.sayHello("John Doe"));.
    I even tried to be more explicit and tried:
    @EJB(name="Hello"") private static Hello hello
    with no luck either.
    What am I doing wrong?
    I read all the threads here and no one seems to have problems w/ the provided sample, I even did a fresh re-install of my JDev with no help.
    Thanks,
    Reza

    Hi,
    duplicate post of
    OC4J don't FULLY support injection of EJB implementing multiple interfaces?
    Frank

  • Ejb injected in servlet

    hi
    I injected ejb in my servlet and I have this error in my servlet
    in my if condition that I get this error:
    ava.lang.ClassCastException:
    swch.api.BaseEntity.Terminal cannot be cast to swch.api.BaseEntity.Terminal
    public interface ITrmnlAuthenticationBL{
    public Terminal find ( String serialNo, String password)
                   throws GeneralException;
    @Stateless
    public class TrmnlAuthenticationBL implements ITrmnlAuthenticationBL{
    @EJB IPersistenceManager pm;
    public Terminal find ( String serialNo, String password)
                   throws GeneralException {
    try {
         Terminal terminal = pm.getEntityManager().createQuery("from Terminal where password = :pass and serialNo = :serial ", Terminal.class)
    .setParameter("pass", password).setParameter("serial",serialNo)
    .getSingleResult();
    return terminal;
    }catch (NoResultException e) {
              e.printStackTrace();
              return null;
    catch (Exception e) {
              e.printStackTrace();
              return null;
    public class EnterLet extends HttpServlet {
    @EJB
    private ITrmnlAuthenticationBL trmnlMg;
    @Override
         protected void doPost(HttpServletRequest request, HttpServletResponse response)
                   throws ServletException, IOException {
    String password = request.getParameter("ps");
    Terminal terminal = trmnlMg.find(serialNo, password);
    ****if (terminal == null || ! password.equalsIgnoreCase(terminal.getPassword()) )
    I have error in this line in if condition when I used "terminal.getPassword" and can not cast Termianl from hibernate to
    Terminal entity in my project...
    please explain my mistake
    Edited by: Marzieh on Nov 17, 2011 1:13 AM

    swch.api.BaseEntity.Terminal cannot be cast to swch.api.BaseEntity.TerminalWeird huh? Java is telling you that it cannot cast an object to the exact same type.
    That means that you have classloader conflicts. The same class is loaded by two different classloaders, which probably means that you have a jar with the entity deployed in two different and isolated modules (war, ear, whatever). Even if the two classes are the same, because they come from two different classloaders, to Java they are different classes and not assignable to each other.
    Is all this deployed in the same EAR? If it is you shouldn't be having this problem and you must be doing something really funky in the way you deploy the stuff. If it isn't, you should deploy everything in the same ear to fix the classpath conflicts.

  • EJB injection not working for a Jersey class

    I have a standard EJB3.0 bean defined as follows:
    @Stateless
    @Local(CustomerService.class)
    public class CustomerBean implements CustomerService
    I can successfully reference that EJB using dependency injection from a servlet with the following code:
    public class CustomerServlet extends HttpServlet {
    @EJB(beanName="CustomerBean")
    private CustomerService customerService;
    public void doGet(...) {
    CustomerVO customer = customerService.getCustomerById(id);
    However the same code will not work from a Jersey RESTful service class
    @Path("/{customer}")
    public class CustomerREST {
    @EJB(beanName="CustomerBean")
    private CustomerService customerService;
    @GET
    @Produces("text/plain")
    public String getCustomer(@PathParam("customer") String customerId) {
    CustomerVO customer = customerService.getCustomerById(customerId);
    The Jersey RESTful service class will get executed but throws a NullPointerException because the customerService entity is null.
    The CustomerServlet and the CustomerREST classes are both in the same WebApp, inside an EAR with the EJB.
    They are even in the same package!
    I would appreciate any help.

    Congratulations. You've hit the major limitation of JEE-based dependency injection. You can only inject resources into servlets, filters, listeners, and tag handlers. This is why people eventually move to Spring if they really need dependency injection in non-JEE components.
    You can read the WebLogic manual pages related to this at [http://download.oracle.com/docs/cd/E12840_01/wls/docs103/pdf/webapp.pdf] . Read chapter 8, "WebLogic Annotation for Web Components".

  • How to lookup a EJB 3.0 session bean which is deployed in WebLogic 10.3

    Now Jdeveloper 11.1.1, is giving WebLogic server 10.3.
    With internal WebLogic server, when I created a Sample client, it generated code as:
    private static Context getInitialContext() throws NamingException {
        Hashtable env = new Hashtable();
        // WebLogic Server 10.x connection details
        env.put( Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory" );
        env.put(Context.PROVIDER_URL, "t3://127.0.0.1:7101");
        return new InitialContext( env );
    public static void main(String [] args) {
        try {
            final Context context = getInitialContext();
            DefaultSession defaultSession = (DefaultSession)context.lookup("property-DefaultSession#com.vs.property.model.session.DefaultSession");
        } catch (Exception ex) {
    }How to update the above code to lookup the EJB 3.0 session beans with an external WebLogic server 10.3?
    Is there any documentation available on how to install weblogic, troubleshoot, debug, WebLogic server 10.3?
    regds
    -raju

    Raju,
    Hi, to start, here is a tutorial on a quickstart web application using an EJB 3.0 stateless session bean that fronts a container managed EclipseLink JPA entity manager on WebLogic 10.3, you will find references there to other general WebLogic documentation.
    [http://wiki.eclipse.org/EclipseLink/Examples/JPA/WebLogic_Web_Tutorial]
    using @EJB injection on the client instead of a JNDI lookup as below
    [http://edocs.bea.com/wls/docs103/ejb30/annotations.html#wp1417411]
    1) in your second env.put I noticed that your t3 port is 7101, I usually use the default 7001 - but It looks like this port is valid for the JDeveloper embedded version of WebLogic server runs - just verify that it matches the port of your server.
    2) your name#qualified-name lookup looks ok. Verify that the jndi-name element is set in your weblogic-ejb-jar.xml for non injection clients like the following
    &lt;weblogic-ejb-jar&gt;
    &lt;weblogic-enterprise-bean&gt;
    &lt;ejb-name&gt;ApplicationService&lt;/ejb-name&gt;
    &lt;jndi-name&gt;ApplicationService&lt;/jndi-name&gt;
    3) as a test outside of your application - launch the WebLogic admin console and goto the testing tab of your bean in [Home &gt; Summary of Deployments &gt; "application" &gt; "session bean name"
    thank you
    /michael : http://www.eclipselink.org                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Local Session Bean calling another local Session Bean in EJB 3.0

    Hi,
    In EJB 3.0, I am trying to do JNDI lookup of a local sesion bean from another session bean's helper class.
    I am not using @EJB injection mechanism here, as call to the local session bean is made in a helper class. Helper classes do not support resource injection.
    Following are the EJB class definitions used in my project. Call to "EJB3Local" made from "EJB1" fails as the "EJB2" helper class is calling "EJB1Local"
    @Stateless
    @EJBs({@EJB(name="EJB2Local", beanInterface=EJB2Local.class),
    @EJB(name="EJB3Local", beanInterface=EJB3Local.class)})
    public class EJB1 implements EJB1Remote, EJB1Local{
    public void findEJB3Local(){
    //1. JNDI lookup for EJB3Local ----
    //2. EJB3Local.someFunction()
    @Stateless
    @EJB(name="EJB1Local", beanInterface=EJB1Local.class)
    public class EJB2 implements EJB2Remote, EJB2Local{
    public void findEJB1Local(){
    //1. JNDI lookup EJB1Local
    // 2. Call EJB1Local.findEJB1Local method
    @Stateless
    public class EJB3 implements EJB3Remote, EJB3Local{
    public void someFunction(){}
    A remote call to EJB2.findEJB1Local() will invoke EJb1Local.findEJB3Local method and the call fails with "java:comp/env/EJB3Local" not found in EJB1Local.
    Has anybody encountered an issue like this issue with local interface calling another local interface?
    Thanks,
    Mohan

    To refer a Ejb from another Ejb include <ejb-ref> element
    in ejb-jar.xml
    <session>
    <ejb-name>SessionBeanA</ejb-name>
    <ejb-ref>
    <ejb-ref-name>SessionBeanB</ejb-ref-name>
    <ejb-ref-type>Session</ejb-ref-type>
    <home>com.ejb.SessionBeanBHome</home>
    <remote>com.ejb.SessionBeanB</remote>
    </ejb-ref>
    </session>
    Include a <reference-descriptor> in weblogic-ejb-jar.xml
    <weblogic-enterprise-bean>
    <ejb-name>SessionBeanA</ejb-name>
    <reference-descriptor>
    <ejb-reference-description>
    <ejb-ref-name>SessionBeanB</ejb-ref-name>
    <jndi-name>com.ejb.SessionBeanBHome</jndi-name>
    </ejb-reference-description>
    </reference-descriptor>
    </weblogic-enterprise-bean>
    In SessionBeanA Bean class refer to SessionBeanB with
    a remote reference to SessionBeanB.
    InitialContext initialContext=new InitialContext();
    SessionBeanBHome sessionBeanBHome=(SessionBeanBHome)
    initialContext.lookup("com.ejb.SessionBeanBHome");
    SessionBeanB sessionBeanB=sessionBeanBHome.findByPrimaryKey(primarykey);
    sessionBeanB.update();
    sessionBeanB.getAll();
    thanks,
    Deepak

  • JSF combined with EJB, how??

    Hi @ll,
    I have been trying for some days to combine my JSF pages with EJB Session Beans, but I haven't really found a working way to do it.
    First, I had my session bean directly as the backing bean for the JSF page, but I read somewhere that this isn't "allowed", so I created a helper bean as managed bean. This is now the backing bean for the jsf page and has as attribute the session bean.
    My helper bean:
    public class ManagedHelperBean {
    @EJB private JDDACReaderBeanRemote reader;
    public JDDACReaderBeanRemote getReader() {
         return reader;
    public void setReader(JDDACReaderBeanRemote reader) {
         this.reader = reader;
    }Part of my faces-config.xml
    <managed-bean>
    <managed-bean-name>helper</managed-bean-name>
    <managed-bean-class>com.company.ManagedHelperBean</managed-bean-class>
    <managed-bean-scope>session</managed-bean-scope>
    </managed-bean>Part of my jsp page:
    <h:outputText value="#{helper}"/>
    <h:outputText value="#{helper.reader}"/>Now, the first output in the jsp page works, the second one doesn't. Why can't the property reader be accessed?? What is the correct way to combine JSF with EJB?
    Kind regards,
    Wiebke

    Hello,
    I faced the same problem, but on a Weblogic 10 server.
    The problem with Weblogic 10 is, even if it's "supposed" to be a EE5 compliant server, it is not.
    As described here http://e-docs.bea.com/wls/docs100/webapp/annotateservlet.html , there is no Dependency Injection in JSF managed beans:
    The web container will not process annotations on classes like Java Beans and other helper classes.
    But, WL 10 offers DI on Servlets, Filters and Listeners.
    Here is how I solved it (probably not the best way, but it works for me):
    - created a filter with a list of EJB injected (as it works). For every filtered request, set a list of known (enum) as request attributes mapped each to a EJB service:
    public class EJBInjectFilter implements Filter {
    @EJB
    private MyEJBService ejbRef;
    public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws IOException,
                   ServletException {
    log.debug("Setting EJB ref into request as attribute ");
              req.setAttribute(ServiceEnum.MY_EJB_SERVICE.toString(), ejbRef);
              chain.doFilter(req, resp);     
    - for every managed bean who needs a service you can do something like:
    (MyEJBService) ((HttpServletRequest) FacesContext.getCurrentInstance().
                   getExternalContext().getRequest()).getAttribute(ServiceEnum.MY_EJB_SERVICE.toString())
    to get a reference to service.
    I agree it is a totally not elegant solution. But why does WL 10 say it's a full JEE5 compliant server, and though does not provide DI for managed beans?
    A drawbacks I could think of is performance slow-down (for every request, apply filter, set list of attributes + references into request) - probably it does take some time.
    Let me know your thoughts.
    Edited by: cosminj on Nov 20, 2007 8:16 AM

  • Directory structure for JSF with EJB3 injection

    I currently have a relatively simple JSF application with the following structure:
    ROOT
    |
    |--index.jsp
    |--jsp
    |     |--index.jspx
    |     |--TopMenu.jspx
    |     |--Details.jspx
    |
    |--META-INF
    |--WEB-INF
    |      |--classes
    |            |--example
    |                    |--beans
    |                    |--model
    |                    |--tags
    |      |--lib
    |      |--tlds
    |      |--web.xml
    |      |--faces-config.xmlNow, I need to add a session bean that will be injected into a JSF managed bean, but I don't know where to put it. Actually, I don't know how should a driectory structure look like for an enterprise application which envlves jsp, jsf, servlets and ejb. Can anyone give me an example or point me to a document where I can learn this?

    After further reading, I must say I'm more confused than ever before.
    I've been looking into the examples provided with Sun's Java EE tutorial and what bothers me is that the only mention of EJB in xmls was in the application.xml where EJB's JAR (along with web app's WAR) was listed as a module:
    <module>
      <web>
      <web-uri>dukesbank-war.war</web-uri>
      <context-root>/bank</context-root>
      </web>
    </module>
    <module>
      <ejb>dukesbank-ejb.jar</ejb>
    </module>,
    but what if the web app was not deployed within the same EAR, instead calling the already-deployed EJB? It would have to have a reference to it in it's web.xml, wouldn't it? But, for some reason, I could find no example for this. The only mention of EJBs within web.xml was with <ejb-ref> which seems to be meant for EJB 2 as it requires references to EJB's home and remote interfaces... So, my question would be, what element do I need to add to web.xml to be able to inject an EJB 3 through @EJB annotations, if that particular EJB has already been deployed? Do I need to add anything at all, or is the annotation itself enough (i.e. it stands as a replacement for <ejb-ref>)? Is this app server dependent?
    Also, I keep seeing that EJB injection into JSF managed beans is not supported on JBoss, but then again, I keep seeing the opposite... I really need some guidance on this...
    If I'm making no sense here, please tell me so...

  • Toplink error on EJB-QL

    I have no idea where to go next, I figure that it's a problem in my query.
    My EJB-QL query...
    select object(o) from Alarm o, AlarmAcknowledges p where o.rowNumber < 500 and o.statusLogFk = p.statusLogFk and p.userId = :userId
    I get this error from toplink:
    Exception [TOPLINK-6089] (Oracle TopLink - 10g Release 3 (10.1.3.0.0) (Build 060118)): oracle.toplink.exceptions.QueryException
    Exception Description: The expression has not been initialized correctly. Only a single ExpressionBuilder should be used for a query.
    For parallel expressions, the query class must be provided to the ExpressionBuilder constructor, and the query's ExpressionBuilder must
    always be on the left side of the expression.
    Expression: [
    Base com.navsys.talon.dal.model.AlarmAcknowledges]
    Query: ReadAllQuery(com.navsys.talon.dal.model.Alarm)

    Hi,
    I found a way to correct the mistake.
    In the bean code, I name the Session EJB
    @Stateless(mappedName="sessionPourCMP")
    and I use a lookup in the client
    Context ic = new InitialContext();
    sessionPourCMP = (SessionPourCMPRemote) ic.lookup("sessionPourCMP");
    Everything is fine. Of course, i don't have the EJB "injection", I think; but the example works well now !

Maybe you are looking for

  • Extracting data from SAP system using Shared directory

    Hi, sapian.        I need the detail steps about creation of data store for a sap system in BODS for extraction of data in Direct download method.Can any of you suggest me the steps about it. I need the details about Application server: Working direc

  • How to delete sender's old email address

    Using Mail, Smart addresses picks the old email address even though I've edited Address Book and put in the new one.

  • Group Chart of A/c

    hello all, My client has two company codes and they want to prepare consilidated balance sheet as well as separate b/s  but they have two chart of a/c how the b/s can be mapped to consolidation . Urgent give the steps of configuration points will be

  • Counting Number of retries

    Hi, I use WorkSpace Studio 1.1 and I'd like to know if it's possible to retrieve the number of retries a BS is going to do. For example, I have a BS that calls a specific system 3 times in case the previous one failed. Is it possible to have a variab

  • Installing RTA CC 5.2 NH WAS 700 aborted with language error

    Hi Everybody, I tried to install the RTA CC 5.2 NH according to SAP Note 1001783 on MSP I tried to install the RTA CC 5.2 (File: K-523COINVIRSANH.CAR) via SAINT in the Back-end System (Mandant 000). During the installation the following error message