0

我的项目中有两个模块:

JBoss 6 服务器:

import javax.ejb.*;
@Remote
public interface srv_interface {
    public int test();
}
@Stateless
public class srv_class implements srv_interface {
    public int test()
    {
        return 999;
    }
}

客户端:

public class Main
{
    public static void main( String[] arg ) throws Exception
    {

        Properties props = new Properties();
        props.setProperty("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
        props.setProperty("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces");
        props.setProperty("java.naming.provider.url", "jnp://127.0.0.1:1099");
        Context context = new InitialContext(props);

        Object connectionFacadeRemote = context.lookup("srv_class/remote");
        srv_interface exampleService = (srv_interface) connectionFacadeRemote; // can't get srv_interface anywhere...
    }
}

问题是客户端看不到 srv_interface。如何使客户端模块可见“srv_interface”?

4

1 回答 1

0

您必须将接口复制到客户端模块,请记住,您从 Context 获得的是实现而不是接口本身。

(顺便尝试遵循 [Java 类命名惯例][1])

[1]。http://en.wikipedia.org/wiki/Naming_convention_%28programming%29#Java

于 2013-09-19T16:22:07.817 回答