Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
javax.naming.NameNotFoundException:EJB未绑定_Java_Jakarta Ee_Jboss_Ejb 3.0_Jboss5.x - Fatal编程技术网

javax.naming.NameNotFoundException:EJB未绑定

javax.naming.NameNotFoundException:EJB未绑定,java,jakarta-ee,jboss,ejb-3.0,jboss5.x,Java,Jakarta Ee,Jboss,Ejb 3.0,Jboss5.x,我已经为一个动态web项目创建了一个示例EJB模块,但是当我尝试访问使用EJB的Servlet时,我发现EJB没有绑定 package com.za.tutorial; import javax.ejb.Stateless; @Stateless public class ZASessionBean implements ZASessionBeanLocal { public String demoSessionBean(){ return "demoSessionBean";

我已经为一个动态web项目创建了一个示例EJB模块,但是当我尝试访问使用EJB的Servlet时,我发现EJB没有绑定

package com.za.tutorial;
import javax.ejb.Stateless;     
@Stateless
public class ZASessionBean implements ZASessionBeanLocal {
public String demoSessionBean(){
    return "demoSessionBean";
}
}


package com.za.tutorial;
import javax.ejb.Local;
@Local
public interface ZASessionBeanLocal {
    public String demoSessionBean();
}
我已经创建了一个动态web项目,并在Servlet中使用上述EJB,如下所示

    package com.za.tutorial;

import java.io.IOException;
import java.io.PrintWriter;

import javax.ejb.EJB;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


public class ZaServlet extends HttpServlet {
private static final long serialVersionUID = 1L;

/**
 * @see HttpServlet#HttpServlet()
 */
public ZaServlet() {
    super();
    // TODO Auto-generated constructor stub
}

@EJB(mappedName="ZASessionBean/local")
ZASessionBeanLocal objZASessionBean;
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    System.out.println("#ZaServlet#start");
    PrintWriter out=response.getWriter();
    out.println(objZASessionBean.demoSessionBean());
    System.out.println("#ZaServlet#end");
}



}
javax.naming.NameNotFoundException: ZASessionBean not bound
org.jnp.server.NamingServer.getBinding(NamingServer.java:771)
org.jnp.server.NamingServer.getBinding(NamingServer.java:779)
org.jnp.server.NamingServer.getObject(NamingServer.java:785)
org.jnp.server.NamingServer.lookup(NamingServer.java:396)
org.jnp.interfaces.NamingContext.lookup(NamingContext.java:726)
org.jnp.interfaces.NamingContext.lookup(NamingContext.java:686)
javax.naming.InitialContext.lookup(InitialContext.java:392)
org.jnp.interfaces.NamingContext.resolveLink(NamingContext.java:1346)
org.jnp.interfaces.NamingContext.lookup(NamingContext.java:817)
org.jnp.interfaces.NamingContext.lookup(NamingContext.java:686)
org.jboss.ejb3.JndiUtil.lookup(JndiUtil.java:44)
org.jboss.injection.JndiPropertyInjector.lookup(JndiPropertyInjector.java:75   )
org.jboss.injection.JndiPropertyInjector.inject(JndiPropertyInjector.java:99    )
...........
我用EJB和web项目创建了一个Ear,然后部署在JBoss5中。部署后,我可以看到我的EJB部署在服务器控制台中

但当我访问servlet时,仍然是这样

我得到如下EJB未绑定异常

    package com.za.tutorial;

import java.io.IOException;
import java.io.PrintWriter;

import javax.ejb.EJB;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


public class ZaServlet extends HttpServlet {
private static final long serialVersionUID = 1L;

/**
 * @see HttpServlet#HttpServlet()
 */
public ZaServlet() {
    super();
    // TODO Auto-generated constructor stub
}

@EJB(mappedName="ZASessionBean/local")
ZASessionBeanLocal objZASessionBean;
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    System.out.println("#ZaServlet#start");
    PrintWriter out=response.getWriter();
    out.println(objZASessionBean.demoSessionBean());
    System.out.println("#ZaServlet#end");
}



}
javax.naming.NameNotFoundException: ZASessionBean not bound
org.jnp.server.NamingServer.getBinding(NamingServer.java:771)
org.jnp.server.NamingServer.getBinding(NamingServer.java:779)
org.jnp.server.NamingServer.getObject(NamingServer.java:785)
org.jnp.server.NamingServer.lookup(NamingServer.java:396)
org.jnp.interfaces.NamingContext.lookup(NamingContext.java:726)
org.jnp.interfaces.NamingContext.lookup(NamingContext.java:686)
javax.naming.InitialContext.lookup(InitialContext.java:392)
org.jnp.interfaces.NamingContext.resolveLink(NamingContext.java:1346)
org.jnp.interfaces.NamingContext.lookup(NamingContext.java:817)
org.jnp.interfaces.NamingContext.lookup(NamingContext.java:686)
org.jboss.ejb3.JndiUtil.lookup(JndiUtil.java:44)
org.jboss.injection.JndiPropertyInjector.lookup(JndiPropertyInjector.java:75   )
org.jboss.injection.JndiPropertyInjector.inject(JndiPropertyInjector.java:99    )
...........

我尝试添加具有以下内容的jboss.xml
ZASessionBean ZASessionBean
我把它放在jboss的deploy文件夹中..但仍然面临同样的问题..有人请帮助解决这个问题,在ejb模块中添加jboss.xml..查看服务器日志,查看部署过程中的错误。如果您可以看到关于部署bean的日志,并且没有错误,那么请尝试使用jmx控制台查看向JNDI注册的内容。