java - 野蝇群 : lookup ejb remote interface

标签 java ejb-3.0 microservices wildfly-swarm

我生成了两个简单的野蝇群项目。第一个是具有远程接口(interface)的 EJB 外观,第二个应该查找它并发送消息。所以第二个应该是作为客户端。

我已经习惯了 野蝇群2017.9.4版

我的 EJB 外观查找路径:

        java:global/ejb-one/PingFacade!io.project.core.interfaces.PingFacadeRemote
        java:app/ejb-one/PingFacade!io.project.core.interfaces.PingFacadeRemote
        java:module/PingFacade!io.project.core.interfaces.PingFacadeRemote
        java:jboss/exported/ejb-one/PingFacade!io.project.core.interfaces.PingFacadeRemote
        java:global/ejb-one/PingFacade
        java:app/ejb-one/PingFacade
        java:module/PingFacade

我的客户:

 public static void main(String[] args) {
        BackendConnectionManager manager = new BackendConnectionManager();
        try {
            manager.getPingFacadeRemote().savePingMessage("halloooooo");
        } catch (NamingException ex) {
            Logger.getLogger(BackendConnectionManager.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    public  PingFacadeRemote getPingFacadeRemote() throws NamingException {
        final Hashtable jndiProperties = new Hashtable();
        jndiProperties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
        jndiProperties.put(Context.INITIAL_CONTEXT_FACTORY,  "org.wildfly.naming.client.WildFlyInitialContextFactory");
              jndiProperties.put(Context.PROVIDER_URL,"http-remoting://localhost:8080");
                 //jndiProperties.put(Context.PROVIDER_URL,"http://localhost:8080");
        final Context context = new InitialContext(jndiProperties);

        return (PingFacadeRemote) context
                .lookup("java:global/ejb-one/PingFacade!io.project.core.interfaces.PingFacadeRemote");
    }

向 pom.xml 添加了客户端依赖项

 <dependency>
            <groupId>org.wildfly.swarm</groupId>
            <artifactId>ejb-remote</artifactId>
        </dependency>
        <dependency>
            <groupId>org.wildfly</groupId>
            <artifactId>wildfly-naming</artifactId>
        </dependency> 
        <dependency>
            <groupId>org.jboss</groupId>
            <artifactId>jboss-ejb-client</artifactId>
            <scope>runtime</scope>
        </dependency>  
        <dependency>
            <groupId>org.jboss.xnio</groupId>
            <artifactId>xnio-api</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.jboss.xnio</groupId>
            <artifactId>xnio-nio</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.jboss.remoting3</groupId>
            <artifactId>jboss-remoting</artifactId>
            <version>3.3.3.Final</version>
            <scope>runtime</scope>
        </dependency>        
        <dependency>
            <groupId>org.jboss.sasl</groupId>
            <artifactId>jboss-sasl</artifactId>
            <scope>runtime</scope>
            <version>1.0.5.Final</version>
        </dependency>     
        <dependency>
            <groupId>org.jboss.marshalling</groupId>
            <artifactId>jboss-marshalling-river</artifactId>
            <scope>runtime</scope>
        </dependency>     
        <dependency>
            <groupId>org.jboss.spec.javax.transaction</groupId>
            <artifactId>jboss-transaction-api_1.2_spec</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.jboss.spec.javax.jms</groupId>
            <artifactId>jboss-jms-api_2.0_spec</artifactId>
        </dependency>     
        <dependency>
            <groupId>org.jboss.spec.javax.ejb</groupId>
            <artifactId>jboss-ejb-api_3.2_spec</artifactId>
            <scope>runtime</scope>
        </dependency>

我不知道客户端的全部依赖关系是什么,并且始终如此

javax.naming.CommunicationException: WFNAM00018: Failed to connect to remote host [Root exception is org.jboss.remoting3.ServiceOpenException: Unknown service name]
    at org.wildfly.naming.client.remote.RemoteContext.getRemoteTransport(RemoteContext.java:80)
    at org.wildfly.naming.client.remote.RemoteContext.lambda$lookupNative$0(RemoteContext.java:106)
    at org.wildfly.naming.client.NamingProvider.performExceptionAction(NamingProvider.java:150)
    at org.wildfly.naming.client.remote.RemoteContext.lookupNative(RemoteContext.java:104)
    at org.wildfly.naming.client.AbstractFederatingContext.lookup(AbstractFederatingContext.java:74)
    at org.wildfly.naming.client.AbstractFederatingContext.lookup(AbstractFederatingContext.java:60)
    at org.wildfly.naming.client.WildFlyRootContext.lookup(WildFlyRootContext.java:150)
    at javax.naming.InitialContext.lookup(InitialContext.java:417)
    at io.project.ejbtwo.rest.BackendConnectionManager.getPingFacadeRemote(BackendConnectionManager.java:57)
    at io.project.ejbtwo.rest.BackendConnectionManager.main(BackendConnectionManager.java:43)
Caused by: org.jboss.remoting3.ServiceOpenException: Unknown service name

另外如何解决在客户端查找中传递安全凭证的问题?

这里是项目本身

https://drive.google.com/open?id=0B45Md1_c5-gGQ0p3Q2pURUxOY00

最佳答案

BackendConnectionManager.java中,第57行,您正在尝试查找服务java:global/ejb-one/PingFacade!io.project.core.interfaces.PingFacadeRemote,但它似乎不存在。 PingFacadeRemote 接口(interface)是ejb-core 模块的一部分。是的,您确实在 ejb-one 模块中实现了它,但您将该接口(interface)注册为远程接口(interface) (@Remote(PingFacadeRemote.class),在 PingFacade.java).

您可以尝试将其替换为 java:global/ejb-core/PingFacade!io.project.core.interfaces.PingFacadeRemote

关于java - 野蝇群 : lookup ejb remote interface,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46514002/

相关文章:

hibernate - JPA 注释 = EJB3 注释 = Hibernate 注释?

java - 在等待 api 调用完成时并行调用 N 阻塞 api 调用以充分利用 CPU 的最佳方法是什么?

c# - BDD 和微服务

java - JUnit理论问题

java - org.hibernate.id.IdentifierGenerationException : ids for this class must be manually assigned before calling save()

JAVA:使用While循环打印出与读入的数字一样多的字符

java - TransactionAttribute.REQUIRES_NEW 未使用容器管理事务在 EJB bean 中启动新事务

azure - 如何设置两个都使用 https 端口的微服务?

java - 使用 java API 从案例生成器解决方案调用规则

Java和xpath - xHtml解析问题