简体   繁体   English

javax.naming.NameNotFoundException WildFly上的EJB HelloWorld

[英]javax.naming.NameNotFoundException EJB HelloWorld on WildFly

I am a beginner in EJB 3.1 and trying to run my first Hello World program and getting the NameNotFoundException. 我是EJB 3.1的初学者,试图运行我的第一个Hello World程序并获取NameNotFoundException。

Exception in thread "main" javax.naming.NameNotFoundException: WFNAM00004: Name "global/HelloWorld/HelloWorldBean!api.HelloWorldRemote" is not found
at org.wildfly.naming.client.util.NamingUtils$1.lookupNative(NamingUtils.java:95)
at org.wildfly.naming.client.AbstractContext.lookup(AbstractContext.java:84)
at org.wildfly.naming.client.WildFlyRootContext.lookup(WildFlyRootContext.java:150)
at javax.naming.InitialContext.lookup(InitialContext.java:417)
at driver.HelloWorld.main(HelloWorld.java:27)

Here are my classes 这是我的课

Local Interface: 本地接口:

@Local
 public interface HelloWorldLocal {
public void getHello();
 }

Remote Interface: 远程接口:

@Remote
public interface HelloWorldRemote extends HelloWorldLocal {

 }

Bean Class: 豆类:

@Stateless(name="HelloWroldBean")
public class HelloWorldBean implements HelloWorldLocal, HelloWorldRemote{

@Override
public void getHello() {
    System.out.println("Hello Cheppura");
}

  }

Client: 客户:

public class HelloWorld {

public static void main(String[] args) throws NamingException {
    final Hashtable<String, String> 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");
    Context con = new InitialContext(jndiProperties);

    final String appName = "";
    final String moduleName = "HelloWorld";
    final String beanName = HelloWorldBean.class.getSimpleName();
    final String viewClassName = HelloWorldRemote.class.getName();

    Object ob = con.lookup("java:global" + appName + "/" + moduleName  + "/" + beanName + "!" + viewClassName);

    HelloWorldRemote hw = (HelloWorldRemote) PortableRemoteObject.narrow(ob, HelloWorldRemote.class);

    hw.getHello();
}

} }

Can anyone please advice on this? 任何人都可以对此提出建议吗? Thanks in advance 提前致谢

You've violated the JEE specification, since there is no inheritance in EJB interfaces. 您违反了JEE规范,因为EJB接口中没有继承。

Your Remote interface extends the Local one but such approach goes against the specification. 您的Remote接口扩展了Local接口,但是这种方法违背了规范。 I think such EAR will never deployed correctly, regardless a runtime environment. 我认为,无论运行时环境如何,此类EAR都永远不会正确部署。

If you want to write a less code this way, then create a third interface with the public void getHello(); 如果您想用这种方式编写更少的代码,请使用public void getHello();创建第三个接口public void getHello(); method and extend it in both Local and Remote interfaces. 方法并在LocalRemote接口中对其进行扩展。

public interface Secondary {
    public void getHello();
}

@Remote
public interface HelloWorldRemote extends Secondary {
 }

@Local
 public interface HelloWorldLocal extends Secondary{
 }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM