我对JavaEE还是很陌生,并试图运行一个小Hello World示例(https://ibytecode.com/blog/how-to-create-a-simple-ejb3-project-in-eclipse-jboss-7-1/),但是我对
感到困惑Exception in thread "main" javax.ejb.NoSuchEJBException: EJBCLIENT000079: Unable to discover destination for request for EJB StatelessEJBLocator for "/HelloWorldSessionBean/HelloWorldBean", view is interface com.ibytecode.business.HelloWorld, affinity is None
这可能只是一些初学者的错误,但我在这里迷路了。
这是我的源代码:
HelloWorld.java
package com.ibytecode.business;
import javax.ejb.Remote;
@Remote
public interface HelloWorld {
public String sayHello();
}
HelloWorldBean.java
package com.ibytecode.businesslogic;
import com.ibytecode.business.HelloWorld;
import javax.ejb.Stateless;
/**
* Session Bean implementation class HelloWorldBean
*/
@Stateless
public class HelloWorldBean implements HelloWorld {
public HelloWorldBean() {
}
@Override
public String sayHello() {
return "Hello World !!!";
}
}
我在Eclipse中创建了JBoss 7.1服务器,启动并部署了HelloWorldSessionBean
。看来效果很好:
...
10:23:17,999 INFO [org.jboss.as.ejb3.deployment] (MSC service thread 1-8) WFLYEJB0473: JNDI bindings for session bean named 'HelloWorldBean' in deployment unit 'deployment "HelloWorldSessionBean.jar"' are as follows:
java:global/HelloWorldSessionBean/HelloWorldBean!com.ibytecode.business.HelloWorld
java:app/HelloWorldSessionBean/HelloWorldBean!com.ibytecode.business.HelloWorld
java:module/HelloWorldBean!com.ibytecode.business.HelloWorld
java:jboss/exported/HelloWorldSessionBean/HelloWorldBean!com.ibytecode.business.HelloWorld
java:global/HelloWorldSessionBean/HelloWorldBean
java:app/HelloWorldSessionBean/HelloWorldBean
java:module/HelloWorldBean
...
这是客户端代码:
package com.ibytecode.client;
import java.util.Properties;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import com.ibytecode.business.HelloWorld;
public class EJBApplicationClient {
public static void main(String[] args) {
InitialContext context = null;
HelloWorld bean = null;
try {
Properties properties = new Properties();
properties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
//properties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
properties.put(Context.INITIAL_CONTEXT_FACTORY, "org.wildfly.naming.client.WildFlyInitialContextFactory");
context = new InitialContext(properties);
String lookupName = "ejb:/HelloWorldSessionBean/HelloWorldBean!com.ibytecode.business.HelloWorld";
bean = (HelloWorld) context.lookup(lookupName);
} catch (NamingException e) {
e.printStackTrace();
}
System.out.println(bean.sayHello());
}
}
然后我将jboss-ejb-client.properties
放在类路径中:
endpoint.name=client-endpoint
remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED=false
remote.connections=default
remote.connection.default.host=localhost
remote.connection.default.port = 4447
remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS=false
remote.connection.default.username=admin
remote.connection.default.password=admin
当我将客户端作为纯Java应用程序运行时,得到以下输出:
Mär 07, 2019 2:35:57 PM org.wildfly.naming.client.Version <clinit>
INFO: WildFly Naming version 1.0.7.Final-redhat-1
Mär 07, 2019 2:35:57 PM org.wildfly.security.Version <clinit>
INFO: ELY00001: WildFly Elytron version 1.1.7.Final-redhat-1
Mär 07, 2019 2:35:57 PM org.jboss.ejb.client.naming.ejb.ejbURLContextFactory <clinit>
INFO: EJBCLIENT000064: org.jboss.ejb.client.naming.ejb.ejbURLContextFactory is deprecated; new applications should use org.wildfly.naming.client.WildFlyInitialContextFactory instead
Mär 07, 2019 2:35:57 PM org.jboss.ejb.client.EJBClient <clinit>
INFO: JBoss EJB Client version 4.0.9.Final-redhat-1
Mär 07, 2019 2:35:57 PM org.jboss.naming.remote.client.InitialContextFactory <clinit>
INFO: WFNAM00025: org.jboss.naming.remote.client.InitialContextFactory is deprecated; new applications should use org.wildfly.naming.client.WildFlyInitialContextFactory instead
Mär 07, 2019 2:35:57 PM org.jboss.ejb.client.legacy.LegacyPropertiesConfiguration configure
INFO: EJBCLIENT000072: Using legacy jboss-ejb-client.properties EJB client configuration
Mär 07, 2019 2:35:57 PM org.xnio.Xnio <clinit>
INFO: XNIO version 3.5.4.Final-redhat-1
Mär 07, 2019 2:35:57 PM org.xnio.nio.NioXnio <clinit>
INFO: XNIO NIO Implementation Version 3.5.4.Final-redhat-1
Mär 07, 2019 2:35:57 PM org.jboss.ejb.client.legacy.RemotingLegacyConfiguration getConfiguredEndpoint
INFO: EJBCLIENT000070: Using legacy jboss-ejb-client.properties Remoting configuration
Mär 07, 2019 2:35:57 PM org.jboss.remoting3.EndpointImpl <clinit>
INFO: JBoss Remoting version 5.0.5.Final-redhat-1
Mär 07, 2019 2:35:57 PM org.jboss.ejb.client.legacy.ElytronLegacyConfiguration getConfiguredAuthenticationContext
INFO: EJBCLIENT000069: Using legacy jboss-ejb-client.properties security configuration
Exception in thread "main" javax.ejb.NoSuchEJBException: EJBCLIENT000079: Unable to discover destination for request for EJB StatelessEJBLocator for "/HelloWorldSessionBean/HelloWorldBean", view is interface com.ibytecode.business.HelloWorld, affinity is None
at org.jboss.ejb.client.EJBClientInvocationContext.getResult(EJBClientInvocationContext.java:567)
at org.jboss.ejb.client.EJBClientInvocationContext.getResult(EJBClientInvocationContext.java:503)
at org.jboss.ejb.protocol.remote.RemotingEJBClientInterceptor.handleInvocationResult(RemotingEJBClientInterceptor.java:56)
at org.jboss.ejb.client.EJBClientInvocationContext.getResult(EJBClientInvocationContext.java:569)
at org.jboss.ejb.client.EJBClientInvocationContext.getResult(EJBClientInvocationContext.java:503)
at org.jboss.ejb.client.TransactionPostDiscoveryInterceptor.handleInvocationResult(TransactionPostDiscoveryInterceptor.java:133)
at org.jboss.ejb.client.EJBClientInvocationContext.getResult(EJBClientInvocationContext.java:569)
at org.jboss.ejb.client.EJBClientInvocationContext.getResult(EJBClientInvocationContext.java:503)
at org.jboss.ejb.client.DiscoveryEJBClientInterceptor.handleInvocationResult(DiscoveryEJBClientInterceptor.java:108)
at org.jboss.ejb.client.EJBClientInvocationContext.getResult(EJBClientInvocationContext.java:569)
at org.jboss.ejb.client.EJBClientInvocationContext.getResult(EJBClientInvocationContext.java:503)
at org.jboss.ejb.client.NamingEJBClientInterceptor.handleInvocationResult(NamingEJBClientInterceptor.java:78)
at org.jboss.ejb.client.EJBClientInvocationContext.getResult(EJBClientInvocationContext.java:569)
at org.jboss.ejb.client.EJBClientInvocationContext.getResult(EJBClientInvocationContext.java:503)
at org.jboss.ejb.client.TransactionInterceptor.handleInvocationResult(TransactionInterceptor.java:172)
at org.jboss.ejb.client.EJBClientInvocationContext.getResult(EJBClientInvocationContext.java:569)
at org.jboss.ejb.client.EJBClientInvocationContext.getResult(EJBClientInvocationContext.java:503)
at org.jboss.ejb.client.EJBClientInvocationContext.awaitResponse(EJBClientInvocationContext.java:913)
at org.jboss.ejb.client.EJBInvocationHandler.invoke(EJBInvocationHandler.java:177)
at org.jboss.ejb.client.EJBInvocationHandler.invoke(EJBInvocationHandler.java:112)
at com.sun.proxy.$Proxy0.sayHello(Unknown Source)
at com.ibytecode.client.EJBApplicationClient.main(EJBApplicationClient.java:53)
Suppressed: java.net.ConnectException: Connection refused: no further information
at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
at sun.nio.ch.SocketChannelImpl.finishConnect(Unknown Source)
at org.xnio.nio.WorkerThread$ConnectHandle.handleReady(WorkerThread.java:327)
at org.xnio.nio.WorkerThread.run(WorkerThread.java:591)
at ...asynchronous invocation...(Unknown Source)
at org.jboss.remoting3.EndpointImpl.connect(EndpointImpl.java:570)
at org.jboss.remoting3.EndpointImpl.connect(EndpointImpl.java:536)
at org.jboss.remoting3.ConnectionInfo$None.getConnection(ConnectionInfo.java:82)
at org.jboss.remoting3.ConnectionInfo.getConnection(ConnectionInfo.java:55)
at org.jboss.remoting3.EndpointImpl.doGetConnection(EndpointImpl.java:487)
at org.jboss.remoting3.EndpointImpl.getConnectedIdentity(EndpointImpl.java:433)
at org.jboss.remoting3.Endpoint.getConnectedIdentity(Endpoint.java:122)
at org.jboss.remoting3.Endpoint.getConnectedIdentity(Endpoint.java:135)
at org.jboss.remoting3.Endpoint.getConnection(Endpoint.java:212)
at org.jboss.ejb.client.legacy.RemotingLegacyConfiguration.getConfiguredEndpoint(RemotingLegacyConfiguration.java:81)
at org.jboss.remoting3.ConfigurationEndpointSupplier$Holder.lambda$static$0(ConfigurationEndpointSupplier.java:58)
at java.security.AccessController.doPrivileged(Native Method)
at org.jboss.remoting3.ConfigurationEndpointSupplier$Holder.<clinit>(ConfigurationEndpointSupplier.java:45)
at org.jboss.remoting3.ConfigurationEndpointSupplier.get(ConfigurationEndpointSupplier.java:84)
at org.jboss.remoting3.ConfigurationEndpointSupplier.get(ConfigurationEndpointSupplier.java:40)
at org.wildfly.common.context.ContextManager.getPrivileged(ContextManager.java:282)
at org.jboss.remoting3.Endpoint.getCurrent(Endpoint.java:80)
at org.jboss.ejb.protocol.remote.RemotingEJBDiscoveryProvider.<init>(RemotingEJBDiscoveryProvider.java:92)
at org.jboss.ejb.protocol.remote.RemoteTransportProvider.notifyRegistered(RemoteTransportProvider.java:43)
at org.jboss.ejb.client.EJBClientContext.<init>(EJBClientContext.java:275)
at org.jboss.ejb.client.EJBClientContext$Builder.build(EJBClientContext.java:788)
at org.jboss.ejb.client.ConfigurationBasedEJBClientContextSelector.loadConfiguration(ConfigurationBasedEJBClientContextSelector.java:71)
at org.jboss.ejb.client.ConfigurationBasedEJBClientContextSelector.<clinit>(ConfigurationBasedEJBClientContextSelector.java:52)
at org.jboss.ejb.client.EJBClientContext.getDefault(EJBClientContext.java:109)
at org.wildfly.common.context.ContextManager.getPrivileged(ContextManager.java:282)
at org.jboss.ejb.client.EJBClientContext.getCurrent(EJBClientContext.java:798)
at org.jboss.ejb.client.EJBInvocationHandler.invoke(EJBInvocationHandler.java:161)
... 3 more
Suppressed: java.net.ConnectException: Connection refused: no further information
at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
at sun.nio.ch.SocketChannelImpl.finishConnect(Unknown Source)
at org.xnio.nio.WorkerThread$ConnectHandle.handleReady(WorkerThread.java:327)
at org.xnio.nio.WorkerThread.run(WorkerThread.java:591)
at ...asynchronous invocation...(Unknown Source)
at org.jboss.remoting3.EndpointImpl.connect(EndpointImpl.java:570)
at org.jboss.remoting3.EndpointImpl.connect(EndpointImpl.java:536)
at org.jboss.remoting3.ConnectionInfo$None.getConnection(ConnectionInfo.java:82)
at org.jboss.remoting3.ConnectionInfo.getConnection(ConnectionInfo.java:55)
at org.jboss.remoting3.EndpointImpl.doGetConnection(EndpointImpl.java:487)
at org.jboss.remoting3.EndpointImpl.getConnectedIdentity(EndpointImpl.java:433)
at org.jboss.remoting3.UncloseableEndpoint.getConnectedIdentity(UncloseableEndpoint.java:51)
at org.jboss.ejb.protocol.remote.RemotingEJBDiscoveryProvider.getConnectedIdentityUsingClusterEffective(RemotingEJBDiscoveryProvider.java:311)
at org.jboss.ejb.protocol.remote.RemotingEJBDiscoveryProvider$DiscoveryAttempt.lambda$connectAndDiscover$0(RemotingEJBDiscoveryProvider.java:384)
at java.security.AccessController.doPrivileged(Native Method)
at org.jboss.ejb.protocol.remote.RemotingEJBDiscoveryProvider$DiscoveryAttempt.connectAndDiscover(RemotingEJBDiscoveryProvider.java:384)
at org.jboss.ejb.protocol.remote.RemotingEJBDiscoveryProvider$DiscoveryAttempt.countDown(RemotingEJBDiscoveryProvider.java:468)
at org.jboss.ejb.protocol.remote.RemotingEJBDiscoveryProvider$DiscoveryAttempt$1.handleFailed(RemotingEJBDiscoveryProvider.java:350)
at org.jboss.ejb.protocol.remote.RemotingEJBDiscoveryProvider$DiscoveryAttempt$1.handleFailed(RemotingEJBDiscoveryProvider.java:342)
at org.xnio.IoFuture$HandlingNotifier.notify(IoFuture.java:215)
at org.xnio.AbstractIoFuture$NotifierRunnable.run(AbstractIoFuture.java:720)
at org.jboss.remoting3.EndpointImpl$TrackingExecutor.lambda$execute$0(EndpointImpl.java:926)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
我将jboss-client.jar
中的$JBOSS-HOME/bin/client
放在类路径中。
任何建议我做错了什么? 非常感谢!
编辑:可能值得注意的是,由于bean.sayHello()
导致发生了NoSuchEJBException。因此,也许这不是查找问题,而是连接问题?
答案 0 :(得分:0)
您似乎对HelloWorldBean的lookupName(JNDI)错误。试试这个:
java:jboss/HelloWorldBean
此外,您还可以观看本文并在JBOSS管理页面上找到您的bean的正确JNDI名称。 How to find JNDI name in JBoss-7?