Announcement Announcement Module
Collapse
No announcement yet.
Cannot locate EJB via JNDI in WebSphere Server Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Cannot locate EJB via JNDI in WebSphere Server

    Hi,

    I'm trying to access a session bean with the LocalStatelessSessionProxyFactoryBean. The bean is configured as following:
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE beans PUBLIC "//SPRING//DTD BEAN//EN" "http&#58;//www.springframework.org/dtd/spring-beans.dtd">
    <beans>
    
    	<bean id="helloWorldService"
    		class="org.springframework.ejb.access.LocalStatelessSessionProxyFactoryBean" lazy-init="true">
    		<property name="jndiName">
    			<value>java&#58;comp/env/ejb/helloWorldService</value>
    		</property>
    		<property name="resourceRef">
    			<value>true</value>
    		</property>
    		<property name="businessInterface">
    			<value>de.gish.am.service.HelloWorldService</value>
    		</property>
    		 <property name="jndiEnvironment">
    			<props>
    			<!-- provide WebSphere AppServer 5.1 environment properties here -->
    			<prop key="java.naming.factory.initial">com.ibm.websphere.naming.WsnInitialContextFactory</prop>
    			<prop key="java.naming.provider.url">iiop&#58;//localhost&#58;2809/</prop>
    			</props> 
    		</property>
    	</bean>
    
    </beans>
    I've configured the EJB as following
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <ejb-jar id="ejb-jar_ID" version="2.1" xmlns="http&#58;//java.sun.com/xml/ns/j2ee" xmlns&#58;xsi="http&#58;//www.w3.org/2001/XMLSchema-instance" xsi&#58;schemaLocation="http&#58;//java.sun.com/xml/ns/j2ee http&#58;//java.sun.com/xml/ns/j2ee/ejb-jar_2_1.xsd">
    	<display-name>
    	amEJB</display-name>
    	<enterprise-beans>
    		<session id="HelloWorldService">
    			<ejb-name>HelloWorldService</ejb-name>
    			<local-home>ejbs.HelloWorldServiceLocalHome</local-home>
    			<local>ejbs.HelloWorldServiceLocal</local>
    			<ejb-class>ejbs.HelloWorldServiceBean</ejb-class>
    			<session-type>Stateless</session-type>
    			<transaction-type>Container</transaction-type>
    		</session>
    	</enterprise-beans>
    </ejb-jar>
    And defined the JNDI name to
    Code:
    ejb/helloWorldService
    I'm now trying to access this EJB with a very simple servlet

    Code:
    protected void doGet&#40;HttpServletRequest request, HttpServletResponse response&#41; throws ServletException, IOException &#123;
    		ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext&#40;"beans.xml"&#41;;
    		HelloWorldService service = &#40;HelloWorldService&#41;context.getBean&#40;"helloWorldService"&#41;;
    		response.getWriter&#40;&#41;.write&#40;service.echo&#40;"Hello World"&#41;&#41;;
    	&#125;
    which trows a BeanCreationException:
    Code:
    Error creating bean with name 'helloWorldService' defined in class path resource &#91;beans.xml&#93;&#58; Initialization of bean failed; nested exception is javax.naming.NameNotFoundException&#58; Name comp/env/ejb not found in context "java&#58;".
    javax.naming.NameNotFoundException&#58; Name comp/env/ejb not found in context "java&#58;".
    	at com.ibm.ws.naming.ipbase.NameSpace.getParentCtxInternal&#40;NameSpace.java&#58;1716&#41;
    	at com.ibm.ws.naming.ipbase.NameSpace.lookupInternal&#40;NameSpace.java&#58;1062&#41;
    	at com.ibm.ws.naming.ipbase.NameSpace.lookup&#40;NameSpace.java&#58;985&#41;
    	at com.ibm.ws.naming.urlbase.UrlContextImpl.lookup&#40;UrlContextImpl.java&#58;1263&#41;
    	at com.ibm.ws.naming.java.javaURLContextRoot.lookup&#40;javaURLContextRoot.java&#58;198&#41;
    	at com.ibm.ws.naming.java.javaURLContextRoot.lookup&#40;javaURLContextRoot.java&#58;139&#41;
    	at javax.naming.InitialContext.lookup&#40;InitialContext.java&#58;361&#41;
    	at org.springframework.jndi.JndiTemplate$1.doInContext&#40;JndiTemplate.java&#58;123&#41;
    	at org.springframework.jndi.JndiTemplate.execute&#40;JndiTemplate.java&#58;85&#41;
    	at org.springframework.jndi.JndiTemplate.lookup&#40;JndiTemplate.java&#58;121&#41;
    	at org.springframework.jndi.JndiLocatorSupport.lookup&#40;JndiLocatorSupport.java&#58;71&#41;
    	at org.springframework.jndi.JndiObjectLocator.lookup&#40;JndiObjectLocator.java&#58;85&#41;
    	at org.springframework.ejb.access.AbstractSlsbInvokerInterceptor.refreshHome&#40;AbstractSlsbInvokerInterceptor.java&#58;102&#41;
    	at org.springframework.ejb.access.AbstractSlsbInvokerInterceptor.afterPropertiesSet&#40;AbstractSlsbInvokerInterceptor.java&#58;90&#41;
    	at org.springframework.ejb.access.LocalStatelessSessionProxyFactoryBean.afterPropertiesSet&#40;LocalStatelessSessionProxyFactoryBean.java&#58;83&#41;
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods&#40;AbstractAutowireCapableBeanFactory.java&#58;962&#41;
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean&#40;AbstractAutowireCapableBeanFactory.java&#58;354&#41;
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean&#40;AbstractBeanFactory.java&#58;223&#41;
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean&#40;AbstractBeanFactory.java&#58;147&#41;
    	at org.springframework.context.support.AbstractApplicationContext.getBean&#40;AbstractApplicationContext.java&#58;536&#41;
    	at HelloWorldServlet.doGet&#40;HelloWorldServlet.java&#58;37&#41;
    Has anybody any tipps, what to do, to get EJB support running on a WebSphere enviroment?

    Thx
    Joerg

  • #2
    Websphere (6.0) session bean access problem from spring

    I have faced the exact same situation with Websphere 6.0.2
    So, if anybosy has done JNDI access of Websphere container, please help.

    Thanks
    ----------------------------

    The following code from a test client outside of spring works fine by accessing the session bean
    in the websphere container

    public class TestJMS {

    public static void main(String[] args) {
    try {

    Properties p = new Properties();

    String nodeName = "machineName";
    String baseJNDI = "cell/nodes/" + nodeName + "Node03/servers/server1/";
    p.put("java.naming.factory.initial",
    "com.sun.jndi.cosnaming.CNCtxFactory");
    p.put("java.naming.provider.url", "corbaloc:iiop:" + nodeName
    + ":2809");
    Context context = new InitialContext(p);

    EventPublisherHome ephome = (EventPublisherHome)context.lookup(baseJNDI+"ejb/ejbs/EventPublisherHome");
    EventPublisher eventPublisher = (EventPublisher)ephome.create();
    eventPublisher.publishEvent();

    }catch(Exception e)
    {
    System.out.println("Exception while sending a message");
    }
    }
    }


    I am trying to make the program work from spring here is my configuration. I get the following exception

    Exception in mainorg.springframework.beans.factory.BeanCreation Exception: Error creating bean with name
    'jmsQueueSender' defined in file [C:\testSpring\src\java\com\tdemand\common\common1. xml]:
    Can't resolve reference to bean 'eventPublisher' while setting property 'eventPublisher';
    nested exception is org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'eventPublisher'
    defined in file [C:\testSpring\src\java\com\tdemand\common\common1. xml]: Initialization of bean failed; nested exception
    is javax.naming.NameNotFoundException: null



    <bean id="jmsQueueSender" class="com.tdemand.common.JmsQueueSender">

    <property name="eventPublisher" ref="eventPublisher"/>

    </bean>

    <bean id="eventPublisher" class="org.springframework.ejb.access.SimpleRemote StatelessSessionProxyFactoryBean"
    lazy-init="true">


    <property name="jndiName">
    <value>cell/nodes/machineNameNode03/servers/server1/ejb/ejbs/eventPublisher</value>
    </property>

    <property name="jndiEnvironment">
    <props>
    <prop key="java.naming.factory.initial">com.sun.jndi.cos naming.CNCtxFactory</prop>
    <prop key="java.naming.provider.url">corbaloc:iiop:machi neName:2809</prop>
    </props>
    </property>

    <property name="businessInterface" value="ejbs.EventPublisher"/>
    </bean>

    Comment


    • #3
      I had the same problem with WebSphere using Local EJBs and found I had to place "local:" in front of the jndiName.

      Example:
      Code:
      <property name="jndiName">
          <value>local&#58;ejb/helloWorldService</value>
      </property>

      Comment


      • #4
        Hi kjusf3,

        Thanks for your help.

        I have a couple of questions.

        1. In your JNDI look of the session bean you are not giving the long jndi name like 'cell/nodes/machineNameNode03/servers/server1/ejb/ejbs/EventPublisher'
        which I had to give, to access from a test client not using spring.
        Your session bean jndi name looks very simple unlike mine.

        So, what Provider URL and naming factory did you use to just access local:ejb/someService

        2. Have you deployed your application in the same JVM as the Websphere server to access the session beans locally?

        3. What version of Websphere was that?

        Thanks a lot for your help.

        Comment


        • #5
          I have found the problem and fixed it. Replace the following text in the above configuration, and it will work.

          <property name="jndiName">
          <value>cell/nodes/machineNameNode03/servers/server1/ejb/ejbs/EventPublisherHome</value>
          </property>

          Changed EventPublisher -> EventPublisherHome.

          So, you need to give the home interface name and not the remote interface name in the config file

          Comment


          • #6
            I know its a way old post, but I am facing a similar problem. Can u let me know how u fixed this problem. I am trying to run this on WAS 6

            Originally posted by jherbst
            Hi,

            I'm trying to access a session bean with the LocalStatelessSessionProxyFactoryBean. The bean is configured as following:
            Code:
            <?xml version="1.0" encoding="UTF-8"?>
            <!DOCTYPE beans PUBLIC "//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
            <beans>
            
            	<bean id="helloWorldService"
            		class="org.springframework.ejb.access.LocalStatelessSessionProxyFactoryBean" lazy-init="true">
            		<property name="jndiName">
            			<value>java:comp/env/ejb/helloWorldService</value>
            		</property>
            		<property name="resourceRef">
            			<value>true</value>
            		</property>
            		<property name="businessInterface">
            			<value>de.gish.am.service.HelloWorldService</value>
            		</property>
            		 <property name="jndiEnvironment">
            			<props>
            			<!-- provide WebSphere AppServer 5.1 environment properties here -->
            			<prop key="java.naming.factory.initial">com.ibm.websphere.naming.WsnInitialContextFactory</prop>
            			<prop key="java.naming.provider.url">iiop://localhost:2809/</prop>
            			</props> 
            		</property>
            	</bean>
            
            </beans>
            I've configured the EJB as following
            Code:
            <?xml version="1.0" encoding="UTF-8"?>
            <ejb-jar id="ejb-jar_ID" version="2.1" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/ejb-jar_2_1.xsd">
            	<display-name>
            	amEJB</display-name>
            	<enterprise-beans>
            		<session id="HelloWorldService">
            			<ejb-name>HelloWorldService</ejb-name>
            			<local-home>ejbs.HelloWorldServiceLocalHome</local-home>
            			<local>ejbs.HelloWorldServiceLocal</local>
            			<ejb-class>ejbs.HelloWorldServiceBean</ejb-class>
            			<session-type>Stateless</session-type>
            			<transaction-type>Container</transaction-type>
            		</session>
            	</enterprise-beans>
            </ejb-jar>
            And defined the JNDI name to
            Code:
            ejb/helloWorldService
            I'm now trying to access this EJB with a very simple servlet

            Code:
            protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            		ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("beans.xml");
            		HelloWorldService service = (HelloWorldService)context.getBean("helloWorldService");
            		response.getWriter().write(service.echo("Hello World"));
            	}
            which trows a BeanCreationException:
            Code:
            Error creating bean with name 'helloWorldService' defined in class path resource [beans.xml]: Initialization of bean failed; nested exception is javax.naming.NameNotFoundException: Name comp/env/ejb not found in context "java:".
            javax.naming.NameNotFoundException: Name comp/env/ejb not found in context "java:".
            	at com.ibm.ws.naming.ipbase.NameSpace.getParentCtxInternal(NameSpace.java:1716)
            	at com.ibm.ws.naming.ipbase.NameSpace.lookupInternal(NameSpace.java:1062)
            	at com.ibm.ws.naming.ipbase.NameSpace.lookup(NameSpace.java:985)
            	at com.ibm.ws.naming.urlbase.UrlContextImpl.lookup(UrlContextImpl.java:1263)
            	at com.ibm.ws.naming.java.javaURLContextRoot.lookup(javaURLContextRoot.java:198)
            	at com.ibm.ws.naming.java.javaURLContextRoot.lookup(javaURLContextRoot.java:139)
            	at javax.naming.InitialContext.lookup(InitialContext.java:361)
            	at org.springframework.jndi.JndiTemplate$1.doInContext(JndiTemplate.java:123)
            	at org.springframework.jndi.JndiTemplate.execute(JndiTemplate.java:85)
            	at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:121)
            	at org.springframework.jndi.JndiLocatorSupport.lookup(JndiLocatorSupport.java:71)
            	at org.springframework.jndi.JndiObjectLocator.lookup(JndiObjectLocator.java:85)
            	at org.springframework.ejb.access.AbstractSlsbInvokerInterceptor.refreshHome(AbstractSlsbInvokerInterceptor.java:102)
            	at org.springframework.ejb.access.AbstractSlsbInvokerInterceptor.afterPropertiesSet(AbstractSlsbInvokerInterceptor.java:90)
            	at org.springframework.ejb.access.LocalStatelessSessionProxyFactoryBean.afterPropertiesSet(LocalStatelessSessionProxyFactoryBean.java:83)
            	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:962)
            	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:354)
            	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:223)
            	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:147)
            	at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:536)
            	at HelloWorldServlet.doGet(HelloWorldServlet.java:37)
            Has anybody any tipps, what to do, to get EJB support running on a WebSphere enviroment?

            Thx
            Joerg

            Comment


            • #7
              By looking at the exception, it looks like your JNDI name has problem.

              Comment


              • #8
                Sorry, forgot to mention. When I say JNDI name has problem I meant to say check your resource references for that EJB.

                Comment


                • #9
                  Hello,

                  I access local EJBs in Websphere without problems. BTW to access a local EJB you have to be in the same JVM (and you cannot be in a Thread you created yourself). I access local EJBs from servlets...

                  I the websphere JVM you don't have to specify JNDI properties.

                  Here is my config: (I use a ResourceRef to my EJB defined in my web.xml file)

                  ejb-jar.xml:
                  <session id="SessionService">
                  <ejb-name>SessionCleaningService</ejb-name>
                  <local-home>ch.xxx.fwk.context.ejb.SessionCleaningService LocalHome</local-home>
                  <local>ch.xxx.fwk.context.ejb.SessionCleaningServi ceLocal</local>
                  <ejb-class>ch.xxx.fwk.context.ejb.SessionCleaningServic eBean</ejb-class>
                  <session-type>Stateless</session-type>
                  <transaction-type>Container</transaction-type>
                  </session>

                  web.xml:
                  <ejb-local-ref id="EJBLocalRef_1146660600738">
                  <description></description>
                  <ejb-ref-name>ejb/sessionCleaningService</ejb-ref-name>
                  <ejb-ref-type>Session</ejb-ref-type>
                  <local-home>ch.xxx.fwk.context.ejb.SessionCleaningService LocalHome</local-home>
                  <local>ch.xxx.fwk.context.ejb.SessionCleaningServi ceLocal</local>
                  <ejb-link>LOCAL_FACADE.jar#SessionCleaningService</ejb-link>
                  </ejb-local-ref>

                  applicationContext.xml:
                  <bean id="sessionCleaningService"
                  class="org.springframework.ejb.access.LocalStatele ssSessionProxyFactoryBean">
                  <property name="jndiName">
                  <value>ejb/sessionCleaningService</value>
                  </property>
                  <property name="resourceRef">
                  <value>true</value>
                  </property>
                  <property name="businessInterface">
                  <value>ch.xxx.fwk.context.session.SessionCleaningS ervice</value>
                  </property>
                  </bean>

                  Comment

                  Working...
                  X