-
Dec 7th, 2005, 03:54 AM
#1
Cannot locate EJB via JNDI in Weblogic Server
Hi,
I'm trying to access a session bean with the LocalStatelessSessionProxyFactoryBean. The bean is in WAR file and configured as following:
Code:
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="echoService" class="org.springframework.ejb.access.LocalStatele ssSessionProxyFactoryBean" lazy-init="true">
<property name="jndiEnvironment">
<props>
<prop key = "javax.naming.factory.initial">weblogic.jndi.WLIni tialContextFactory</prop>
<prop key = "javax.naming.provider.url">t3://localhost:7001</prop>
</props>
</property>
<property name="jndiName">
<value>ejb/echoService</value>
</property>
<property name="resourceRef">
<value>true</value>
</property>
<property name="businessInterface">
<value>com.sunil.EchoService</value>
</property>
</bean>
</beans>
The bean is in JAR file and configured as following:
Code:
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="echoService" class="com.sunil.EchoServiceImpl"/>
</beans>
I've configured the EJB as following
ejb-jar.xml Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE ejb-jar PUBLIC '-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN' 'http://java.sun.com/dtd/ejb-jar_2_0.dtd'>
<ejb-jar>
<enterprise-beans>
<session>
<description>Echo Service Bean</description>
<ejb-name>EchoServiceEJB</ejb-name>
<local-home>com.sunil.EchoServiceHome</local-home>
<local>com.sunil.EchoServiceLocal</local>
<ejb-class>com.sunil.EchoServiceEJB</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
<env-entry>
<env-entry-name>ejb/BeanFactoryPath</env-entry-name>
<env-entry-type>java.lang.String</env-entry-type>
<env-entry-value>applicationContext.xml</env-entry-value>
</env-entry>
</session>
</enterprise-beans>
<assembly-descriptor>
<container-transaction>
<method>
<ejb-name>EchoServiceEJB</ejb-name>
<method-intf>Local</method-intf>
<method-name>echo</method-name>
</method>
<trans-attribute>RequiresNew</trans-attribute>
</container-transaction>
</assembly-descriptor>
</ejb-jar>
weblogic-ejb-jar.xml Code:
<?xml version="1.0"?>
<!DOCTYPE weblogic-ejb-jar PUBLIC '-//BEA Systems, Inc.//DTD WebLogic 8.1.0 EJB//EN' 'http://www.bea.com/servers/wls810/dtd/weblogic-ejb-jar.dtd' >
<weblogic-ejb-jar>
<weblogic-enterprise-bean>
<ejb-name>EchoServiceEJB</ejb-name>
<local-jndi-name>ejb/echoService</local-jndi-name>
</weblogic-enterprise-bean>
</weblogic-ejb-jar>
And defined the JNDI name to
Code:
ejb/echoService
I am trying to access this ejb via a servlet. Snipshot of code is following:
code:
package su.servlets;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.ServletException;
import java.io.IOException;
import com.sunil.EchoService;
import java.io.PrintWriter;
import org.springframework.context.ApplicationContext;
//import org.springframework.context.support.ClassPathXmlAp plicationContext;
import org.springframework.context.support.FileSystemXmlA pplicationContext;
public class ProxyServlet extends HttpServlet
{
ApplicationContext ctx = null;
public void init()
{
ctx = new FileSystemXmlApplicationContext("D:/utilities/springejb/localremoteweb/WEB-INF/classes/applicationContext.xml");
}
private void doStatelessExample(ApplicationContext ctx, PrintWriter writer) {
// Access the EJB proxy
EchoService service = (EchoService) ctx.getBean("echoService");
writer.write(service.echo("Foo"));
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
PrintWriter writer = response.getWriter();
response.setContentType("text/html");
writer.write("<html><head><title>EJB Samples</title></head>");
writer.write("<body>");
writer.write("<h1>Echo Service (Stateless Session Bean)</h1>");
doStatelessExample(ctx, writer);
writer.write("</body></html>");
}
}
While running it gives following exception:
Error 500--Internal Server Error
org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'echoService' defined in file [D:\utilities\springejb\localremoteweb\WEB-INF\classes\applicationContext.xml]: Initialization of bean failed; nested exception is javax.naming.NameNotFoundException: While trying to look up comp/env/ejb/echoService in /app/webapp/localremote/22257291.
javax.naming.NameNotFoundException: While trying to look up comp/env/ejb/echoService in /app/webapp/localremote/22257291.; remaining name 'comp/env/ejb/echoService'
at weblogic.jndi.internal.BasicNamingNode.newNameNotF oundException(BasicNamingNode.java:897)
at weblogic.jndi.internal.ApplicationNamingNode.looku p(ApplicationNamingNode.java:150)
at weblogic.jndi.internal.WLEventContextImpl.lookup(W LEventContextImpl.java:256)
at weblogic.jndi.internal.WLContextImpl.lookup(WLCont extImpl.java:357)
at weblogic.jndi.factories.java.ReadOnlyContextWrappe r.lookup(ReadOnlyContextWrapper.java:45)
at weblogic.jndi.internal.AbstractURLContext.lookup(A bstractURLContext.java:130)
at javax.naming.InitialContext.lookup(InitialContext. java:347)
at org.springframework.jndi.JndiTemplate$1.doInContex t(JndiTemplate.java:123)
at org.springframework.jndi.JndiTemplate.execute(Jndi Template.java:85)
at org.springframework.jndi.JndiTemplate.lookup(JndiT emplate.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.AbstractSlsbInvoker Interceptor.refreshHome(AbstractSlsbInvokerInterce ptor.java:102)
at org.springframework.ejb.access.AbstractSlsbInvoker Interceptor.afterPropertiesSet(AbstractSlsbInvoker Interceptor.java:90)
at org.springframework.ejb.access.LocalStatelessSessi onProxyFactoryBean.afterPropertiesSet(LocalStatele ssSessionProxyFactoryBean.java:83)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.invokeInitMethods(Abstr actAutowireCapableBeanFactory.java:962)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:354)
at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:223)
at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:147)
at org.springframework.context.support.AbstractApplic ationContext.getBean(AbstractApplicationContext.ja va:536)
at su.servlets.ProxyServlet.doStatelessExample(ProxyS ervlet.java:32)
at su.servlets.ProxyServlet.doGet(ProxyServlet.java:4 3)
at javax.servlet.http.HttpServlet.service(HttpServlet .java:740)
at javax.servlet.http.HttpServlet.service(HttpServlet .java:853)
at weblogic.servlet.internal.ServletStubImpl$ServletI nvocationAction.run(ServletStubImpl.java:996)
at weblogic.servlet.internal.ServletStubImpl.invokeSe rvlet(ServletStubImpl.java:419)
at weblogic.servlet.internal.ServletStubImpl.invokeSe rvlet(ServletStubImpl.java:315)
at weblogic.servlet.internal.WebAppServletContext$Ser vletInvocationAction.run(WebAppServletContext.java :6452)
at weblogic.security.acl.internal.AuthenticatedSubjec t.doAs(AuthenticatedSubject.java:321)
at weblogic.security.service.SecurityManager.runAs(Se curityManager.java:118)
at weblogic.servlet.internal.WebAppServletContext.inv okeServlet(WebAppServletContext.java:3661)
at weblogic.servlet.internal.ServletRequestImpl.execu te(ServletRequestImpl.java:2630)
at weblogic.kernel.ExecuteThread.execute(ExecuteThrea d.java:219)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.ja va:178)
What else i have to configure, any idea...
Thanks
Sunil
-
Mar 10th, 2006, 07:24 AM
#2
Looks remarkably like the ch13 sample from the book ProSpring
Did you get this to work? I'm having the same problem.
-
Mar 10th, 2006, 07:51 AM
#3
Did you check the Weblogic logs to see if the deployment of the EJB itself has been successful?
If yes: maybe it helps to set the "lookupHomeOnStartup" property of your proxy factory bean to "false".
Regards,
Andreas
-
Mar 10th, 2006, 08:26 AM
#4
Could you post your web.xml from your servlet? You might be missing the resource-ref entry that specifies your EJB. Or you could set resoureRef property on your proxy to false and see if that fixes it.
Bill
-
Mar 10th, 2006, 03:25 PM
#5
Thanks for the help!
Bill,
Setting resourceRef to false did the trick. As you indicate, I do not have ejb-local-ref entries in my web.xml, and so I needed to set resourceRef in the app context to false. Thanks again!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules