如何解决线程" main"中的EJBCLIENT000079异常? javax.ejb.NoSuchEJBException?

时间:2017-12-03 12:01:12

标签: java-ee intellij-idea jboss ejb wildfly

我想创建一个EJB项目USE Intellij IDEA.But它有一个错误。我的项目在项目中有拖曳模型,一个是服务器,另一个是客户端。我想启动服务器并运行客户端来执行sayHello函数但是失败了。

我的SessionBean接口和客户端接口

package com.ejb;

import javax.ejb.Remote;

@Remote
public interface HelloWorld {
    public String sayHello(String world);
}

我的SessionBean类

import com.ejb.HelloWorld;

import javax.ejb.Stateless;

@Stateless(name = "HelloWorldEJB")
public class HelloWorldBean implements HelloWorld {
    public HelloWorldBean() {
    }

    @Override
    public String sayHello(String world) {
        return "hello"+world;
    }
}

我的客户类

package com.ejb;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import java.util.Hashtable;

public class HelloWorldClient {
    private static HelloWorld lookupRemoteStatelessEjbBean() throws NamingException {
        final Hashtable jndiProperties = new Hashtable();
        jndiProperties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
        jndiProperties.put("jboss.naming.client.ejb.context", true);
        final Context context = new InitialContext(jndiProperties);
        String namespace="ejb:/EJBServer_war_exploded/HelloWorldEJB!com.ejb.HelloWorld";
        return (HelloWorld) context.lookup(namespace);
    }
    public static void main(String[] args) throws NamingException {
        HelloWorld helloWorld = lookupRemoteStatelessEjbBean();
        System.out.println(helloWorld);
        String s = helloWorld.sayHello("world");
        System.out.println(s);
    }
}

我的属性(此属性完全放在src文件夹中)

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=8080
remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS=false
remote.connection.default.username=admin
remote.connection.default.password=123456

首先我启动服务器并且intellij IDEA自动将war文件夹放入JBOSS(WildFly)11。我访问了EJB amdin网站,并且正好在服务器中使用war文件夹。 错误代码是

Exception in thread "main" javax.ejb.NoSuchEJBException: EJBCLIENT000079: Unable to discover destination for request for EJB StatelessEJBLocator for "/EJBServer_war_exploded/HelloWorldEJB", view is interface com.ejb.HelloWorld, affinity is None

我不知道如何解决它,我搜索了bing和google。没有人有同样的问题,我该如何解决?

2 个答案:

答案 0 :(得分:2)

对于WildFly11,请使用以下配置:

jndiProperties.put(Context.INITIAL_CONTEXT_FACTORY," org.wildfly.naming.client.WildFlyInitialContextFactory"); jndiProperties.put(Context.PROVIDER_URL," HTTP的远程处理://本地主机:8080&#34);

代替:

jndiProperties.put(Context.URL_PKG_PREFIXES," org.jboss.ejb.client.naming"); jndiProperties.put(" jboss.naming.client.ejb.context",true);

答案 1 :(得分:0)

就我而言,替换字符串

namespace="ejb:/EJBServer_war_exploded/HelloWorldEJB!com.ejb.HelloWorld";

与 字符串

namespace="ejb:/EJBServer_war_exploded/HelloWorldBean!com.ejb.HelloWorld";