在eclipse中,我有一个Web应用程序项目,以及一个包含一个本地EJB的EJB项目, 它们都被添加到一个EAR项目中,当我尝试运行服务器时,似乎每件事情都运行良好,但是当我尝试使用查找方法从servlet查找EJB时,我得到了一个异常,我试过看了整个网络,但我找不到任何解决我的问题的东西。 我正在使用JBoss7.1
服务器加载:
18:16:08,126 INFO [org.jboss.modules] JBoss Modules version 1.1.1.GA
18:16:08,708 INFO [org.jboss.msc] JBoss MSC version 1.0.2.GA
18:16:08,766 INFO [org.jboss.as] JBAS015899: JBoss AS 7.1.1.Final "Brontes" starting
18:16:10,267 INFO [org.xnio] XNIO Version 3.0.3.GA
18:16:10,274 INFO [org.jboss.as.server] JBAS015888: Creating http management service using socket-binding (management-http)
18:16:10,283 INFO [org.xnio.nio] XNIO NIO Implementation Version 3.0.3.GA
18:16:10,295 INFO [org.jboss.remoting] JBoss Remoting version 3.2.3.GA
18:16:10,327 INFO [org.jboss.as.logging] JBAS011502: Removing bootstrap log handlers
18:16:10,352 INFO [org.jboss.as.configadmin] (ServerService Thread Pool -- 26) JBAS016200: Activating ConfigAdmin Subsystem
18:16:10,366 INFO [org.jboss.as.clustering.infinispan] (ServerService Thread Pool -- 31) JBAS010280: Activating Infinispan subsystem.
18:16:10,430 INFO [org.jboss.as.connector] (MSC service thread 1-4) JBAS010408: Starting JCA Subsystem (JBoss IronJacamar 1.0.9.Final)
18:16:10,528 INFO [org.jboss.as.connector.subsystems.datasources] (ServerService Thread Pool -- 27) JBAS010403: Deploying JDBC-compliant driver class org.h2.Driver (version 1.3)
18:16:10,554 INFO [org.jboss.as.naming] (ServerService Thread Pool -- 38) JBAS011800: Activating Naming Subsystem
18:16:10,566 INFO [org.jboss.as.security] (ServerService Thread Pool -- 44) JBAS013101: Activating Security Subsystem
18:16:10,569 INFO [org.jboss.as.osgi] (ServerService Thread Pool -- 39) JBAS011940: Activating OSGi Subsystem
18:16:10,605 INFO [org.jboss.as.webservices] (ServerService Thread Pool -- 48) JBAS015537: Activating WebServices Extension
18:16:10,864 INFO [org.jboss.as.security] (MSC service thread 1-4) JBAS013100: Current PicketBox version=4.0.7.Final
18:16:11,113 INFO [org.jboss.as.naming] (MSC service thread 1-4) JBAS011802: Starting Naming Service
18:16:11,214 INFO [org.jboss.as.mail.extension] (MSC service thread 1-3) JBAS015400: Bound mail session [java:jboss/mail/Default]
18:16:11,557 INFO [org.apache.coyote.http11.Http11Protocol] (MSC service thread 1-3) Starting Coyote HTTP/1.1 on http-localhost-127.0.0.1-8080
18:16:11,636 INFO [org.jboss.ws.common.management.AbstractServerConfig] (MSC service thread 1-1) JBoss Web Services - Stack CXF Server 4.0.2.GA
18:16:11,911 INFO [org.jboss.as.remoting] (MSC service thread 1-3) JBAS017100: Listening on localhost/127.0.0.1:4447
18:16:11,927 INFO [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-1) JBAS010400: Bound data source [java:jboss/datasources/ExampleDS]
18:16:11,931 INFO [org.jboss.as.server.deployment.scanner] (MSC service thread 1-4) JBAS015012: Started FileSystemDeploymentService for directory C:\Users\isgav\Desktop\Java programing\jboss-as- 7.1.1.Final\standalone\deployments
18:16:11,957 INFO [org.jboss.as.server.deployment.scanner] (DeploymentScanner-threads - 1) JBAS015003: Found state.ear in deployment directory. To trigger deployment create a file called state.ear.dodeploy
18:16:12,013 INFO [org.jboss.as.remoting] (MSC service thread 1-4) JBAS017100: Listening on /127.0.0.1:9999
18:16:12,300 INFO [org.jboss.as.server.deployment] (MSC service thread 1-2) JBAS015876: Starting deployment of "state.ear"
18:16:12,363 INFO [org.jboss.as.server.deployment] (MSC service thread 1-3) JBAS015876: Starting deployment of "stateful.jar"
18:16:12,363 INFO [org.jboss.as.server.deployment] (MSC service thread 1-1) JBAS015876: Starting deployment of "statefulWebb.war"
18:16:12,674 INFO [org.jboss.as.ejb3.deployment.processors.EjbJndiBindingsDeploymentUnitProcessor] (MSC service thread 1-1) JNDI bindings for session bean named nums in deployment unit subdeployment "stateful.jar" of deployment "state.ear" are as follows:
java:global/state/stateful/nums!nums.Numbers
java:app/stateful/nums!nums.Numbers
java:module/nums!nums.Numbers
java:global/state/stateful/nums
java:app/stateful/nums
java:module/nums
18:16:13,221 INFO [javax.enterprise.resource.webcontainer.jsf.config] (MSC service thread 1-3) Initializing Mojarra 2.1.7-jbossorg-1 (20120227-1401) for context '/statefulWebb'
18:16:14,515 INFO [org.hibernate.validator.util.Version] (MSC service thread 1-3) Hibernate Validator 4.2.0.Final
18:16:14,727 INFO [org.jboss.web] (MSC service thread 1-3) JBAS018210: Registering web context: /statefulWebb
18:16:14,730 INFO [org.jboss.as] (MSC service thread 1-3) JBAS015951: Admin console listening on http://127.0.0.1:9990
18:16:14,732 INFO [org.jboss.as] (MSC service thread 1-3) JBAS015874: JBoss AS 7.1.1.Final "Brontes" started in 7188ms - Started 220 of 301 services (80 services are passive or on-demand)
18:16:15,609 INFO [org.jboss.as.server] (DeploymentScanner-threads - 2) JBAS018559: Deployed "state.ear"
例外:
18:27:07,982 INFO [org.jboss.ejb.client] (http-localhost-127.0.0.1-8080-1) JBoss EJB Client version 1.0.5.Final
18:27:07,991 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host]. [/statefulWebb].[jsp]] (http-localhost-127.0.0.1-8080-1) Servlet.service() for servlet jsp threw exception: java.lang.IllegalStateException: No EJB receiver available for handling [appName:,modulename:state,distinctname:] combination for invocation context org.jboss.ejb.client.EJBClientInvocationContext@266c6521
at org.jboss.ejb.client.EJBClientContext.requireEJBReceiver(EJBClientContext.java:584) [jboss-ejb-client-1.0.5.Final.jar:1.0.5.Final]
at org.jboss.ejb.client.ReceiverInterceptor.handleInvocation(ReceiverInterceptor.java:119) [jboss-ejb-client-1.0.5.Final.jar:1.0.5.Final]
at org.jboss.ejb.client.EJBClientInvocationContext.sendRequest(EJBClientInvocationContext.java:181) [jboss-ejb-client-1.0.5.Final.jar:1.0.5.Final]
at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:136) [jboss- ejb-client-1.0.5.Final.jar:1.0.5.Final]
at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:121) [jboss- ejb-client-1.0.5.Final.jar:1.0.5.Final]
at org.jboss.ejb.client.EJBInvocationHandler.invoke(EJBInvocationHandler.java:104) [jboss-ejb-client-1.0.5.Final.jar:1.0.5.Final]
at com.sun.proxy.$Proxy12.getNums(Unknown Source)
at org.apache.jsp.index_jsp._jspService(index_jsp.java:137)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) [jbossweb- 7.0.13.Final.jar:]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) [jboss-servlet-api_3.0_spec- 1.0.0.Final.jar:1.0.0.Final]
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:369) [jbossweb-7.0.13.Final.jar:]
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:326) [jbossweb-7.0.13.Final.jar:]
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:253) [jbossweb- 7.0.13.Final.jar:]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) [jboss-servlet-api_3.0_spec-1.0.0.Final.jar:1.0.0.Final]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:840) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:622) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:560) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:488) [jbossweb-7.0.13.Final.jar:]
at com.sun.faces.context.ExternalContextImpl.dispatch(ExternalContextImpl.java:546) [jsf- impl-2.1.7-jbossorg-2.jar:]
at com.sun.faces.application.view.JspViewHandlingStrategy.executePageToBuildView(JspViewHandlingStrategy.java:364) [jsf-impl-2.1.7-jbossorg-2.jar:]
at com.sun.faces.application.view.JspViewHandlingStrategy.buildView(JspViewHandlingStrategy.java:154) [jsf-impl-2.1.7-jbossorg-2.jar:]
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:100) [jsf- impl-2.1.7-jbossorg-2.jar:]
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101) [jsf-impl-2.1.7-jbossorg-2.jar:]
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139) [jsf-impl-2.1.7-jbossorg-2.jar:]
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:594) [jboss-jsf-api_2.1_spec- 2.0.1.Final.jar:2.0.1.Final]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161) [jbossweb-7.0.13.Final.jar:]
at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:153) [jboss-as-web-7.1.1.Final.jar:7.1.1.Final]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:368) [jbossweb- 7.0.13.Final.jar:]
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877) [jbossweb- 7.0.13.Final.jar:]
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:671) [jbossweb-7.0.13.Final.jar:]
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:930) [jbossweb-7.0.13.Final.jar:]
at java.lang.Thread.run(Unknown Source) [rt.jar:1.7.0_45]
Servlet代码:
<%@ page language="java" contentType="text/html; charset=windows-1255"
pageEncoding="windows-1255"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@page import="javax.naming.InitialContext"%>
<%@page import="nums.*" %>
<%@page import="java.util.*" %>
<%@page import="javax.naming.*" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1255">
<title>Insert title here</title>
</head>
<body>
<%!
private InitialContext ctx;
public void init(){
try{
Properties properties = new Properties();
properties.put("jboss.naming.client.ejb.context", true);
properties.put(Context.URL_PKG_PREFIXES,"org.jboss.ejb.client.naming");
ctx=new InitialContext(properties);
}catch(Exception e){e.printStackTrace();}
}
%>
<%
Numbers n=null;
if(session.isNew()){
n=(Numbers)ctx.lookup(getLookupName());
session.setAttribute("numbers",n);
}else{
n=(Numbers)session.getAttribute("numbers");
}
String cmd=request.getParameter("curr");
if(cmd!=null){
if(cmd.equals("exit")){
n.exit();
session.invalidate();
response.sendRedirect("index.jsp");
return;
}else{
try{
System.out.println(n.getTotal());
n.addNum(Integer.parseInt(cmd));
}catch(Exception e){
%>
<font color="red"><%= n.getTotal() %>Not a number !</font>
<%}
}
}
%>
<%!
private String getLookupName() {
String appName = "";
String moduleName = "state";
String distinctName = "";
String beanName = NumbersBean.class.getSimpleName();
final String interfaceName = Numbers.class.getName();
String name = "ejb:" + appName + "/" + moduleName + "/" +
distinctName + "/" + beanName + "!" + interfaceName;
System.out.println(name);
return name;
}
%>
<form action="index.jsp">
<input type="text" name="curr"/>
<input type="submit"/>
</form>
<hr/>
<% if(n!=null&&n.getNums().length>0) {%>
<table border="1">
<% int [] nums=n.getNums();
for(int i=0;i<nums.length;i++){%>
<tr><td><%= i+1 %></td><td><%= nums[i] %></td></tr>
<%} %>
</table>
<hr/>
Total: <%= n.getTotal() %>
<hr/>
<%} %>
<a href="index.jsp?curr=exit">Start from the beginning</a>
</body>
</html>
答案 0 :(得分:0)
我不知道您是如何将EJB部署到服务器的。您必须使用@Remote
注释来利用EJB进行JNDI查找。例如:
@Remote(CallerRemote.class)
请查看this link中的“开发简单EJB3应用程序”和“开发EJB3远程客户端”一节(仅当您尚未检查时!)。
答案 1 :(得分:0)
我发现了问题所在。 它没有用,因为事实证明,如果你把你的项目放在EAR文件下,那么appName应该是EAR的名称,所以把EAR名称放在appName中似乎解决了我的问题
String name = "ejb:" + appName + "/" + moduleName + "/" +
distinctName + "/" + beanName + "!" + interfaceName;