使用JBoss连接EJB

问题描述 投票:0回答:1

我使用JBoss服务器托管EJB。

服务器已启动,当我进入本地主机时会看到主页:8080 (欢迎使用AS 7,您的JBoss Application Server 7正在运行。)

在我的客户项目上,我尝试这样连接:

    private static Calculette lookupRemoteStatelessCalculator() throws NamingException {    
    final Context context = new InitialContext();
    context.addToEnvironment("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
    context.addToEnvironment("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces");
    context.addToEnvironment("java.naming.provider.url", "localhost:8080");

    return (Calculette) context.lookup("ejb/stateless/calculette");
}

运行该错误消息:

Could not obtain connection to any of these urls: localhost:8080 and discovery failed with error: javax.naming.CommunicationException: Receive timed out [Root exception is java.net.SocketTimeoutException: Receive timed out] [Root exception is javax.naming.CommunicationException: Failed to retrieve stub from server localhost:8080 [Root exception is java.io.EOFException]]

我尝试使用jndi.properties,但是遇到了我不明白的错误,当我将参数直接放在上下文中就可以了..

任何主意吗?

谢谢

java jboss ejb
1个回答
0
投票

JNDI查找在其他端口上工作。默认情况下,您将必须使用:

 Properties jndiProps = new Properties();
 jndiProps.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
 jndiProps.put(Context.PROVIDER_URL,"remote://localhost:4447");
 // create a context passing these properties
 Context context = new InitialContext(jndiProps);

请注意,对于不同的JBoss / Wildfly版本,存在不同的方法。

另请参见:https://docs.jboss.org/author/display/AS72/Remote+EJB+invocations+via+JNDI+-+EJB+client+API+or+remote-naming+project

© www.soinside.com 2019 - 2024. All rights reserved.