【问题标题】:How to lookup EJB remoting from a EJB application into a java application?如何将 EJB 远程处理从 EJB 应用程序查找到 Java 应用程序?
【发布时间】:2014-09-26 15:49:19
【问题描述】:

我正在开发两个项目,EJB 项目(我有我所有的 EJB Remote),另一个项目是一个带有 main 方法的简单 java 应用程序。但是当我尝试通过 JNDI 查找 EJB 无状态和远程时,它不起作用。

真的用了很多方法,效果都不好。

这是代码和控制台错误。

1) 当我清理并安装我的 Ejb 项目时,它给了我一个 jar 文件。 2) 我使用 Jboss EAP6。 3)我有一个 jndi.properties 在 src/main/ressouces 里面我有这个:

java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
java.naming.provider.url = localhost:1099

PersonalFactory.java(EJB 项目的 EJB)

import javax.ejb.Remote;
import javax.ejb.Stateless;
import com.lazrak.common.logging.CommonLogger;
import com.lazrak.remotes.IPersonFactoryRemote;

@Remote(IPersonFactoryRemote.class)
@Stateless
public class PersonFactory implements  IPersonFactoryRemote

@Override
public void findMe() {
System.out.println("I'am inside of the method findMe");
}

MyMainClass.java(我有 main 方法,它在第二个 java 项目中)

全部导入...

public class MyMainClass {
public static void main(String[] args) throws Exception {

System.out.println("Main start ");
    invokeStatelessBean();
}

private static void invokeStatelessBean(){

     Hashtable props = new Hashtable();
     props.put(Context.INITIAL_CONTEXT_FACTORY,"org.jnp.interfaces.NamingContextFactory");
     props.put(Context.URL_PKG_PREFIXES,"org.jboss.ejb.client.naming");      
     props.put(Context.PROVIDER_URL,"jnp://localhost:1099");
     InitialContext context = null;

try {
        context = new InitialContext(props);
    } catch (NamingException e) {
        System.out.println("Faild to add properties to InitialContext"+e.getMessage());
    }

try {
    final IPersonFactoryRemote statelessRemoteCalculator = (IPersonFactoryRemote) context
                .lookup("ejb:"+moduleName+"/"+PersonFactory.class.getSimpleName();+"/"+IPersonFactoryRemote.class.getName());
    } catch (NamingException e) {
        System.out.println("EJB Remot doesn't been fined\n"+e.getMessage());
    }
}
}

当我运行我的主应用程序时,它给了我:

Main start
enter 2014-09-26 15:57:26,098 DEBUG org.jboss.logging - InitialContextFactory.java:64 - Logging Provider: org.jboss.logging.Log4jLoggerProvider
Exception in thread "main" java.lang.NoClassDefFoundError: org/jboss/remoting3/spi/ConnectionProviderFactory
at org.jboss.naming.remote.client.InitialContextFactory.<clinit>(InitialContextFactory.java:99)
at org.jboss.naming.remote.client.InitialContextFactory.<clinit>(InitialContextFactory.java:99)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:270)
at com.sun.naming.internal.VersionHelper12.loadClass(VersionHelper12.java:72)
at com.sun.naming.internal.VersionHelper12.loadClass(VersionHelper12.java:61)
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:671)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:307)
at javax.naming.InitialContext.init(InitialContext.java:242)
at javax.naming.InitialContext.<init>(InitialContext.java:216)
at RemoteEJBClient.invokeStatelessBean(RemoteEJBClient.java:42)
at RemoteEJBClient.main(RemoteEJBClient.java:18)
Caused by: java.lang.ClassNotFoundException:
org.jboss.remoting3.spi.ConnectionProviderFactory
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
... 11 more

【问题讨论】:

标签: java ejb-3.0 jndi remote-access jboss-eap-6


【解决方案1】:
props.put(Context.INITIAL_CONTEXT_FACTORY,"org.jnp.interfaces.NamingContextFactory");
props.put(Context.URL_PKG_PREFIXES,"org.jboss.ejb.client.naming");      
props.put(Context.PROVIDER_URL,"jnp://localhost:1099");

这些属性用于连接到较旧的 jboss 版本。对于 eap 6,您必须使用远程处理而不是 jnp。

这是一个向您展示如何连接的教程

http://www.mastertheboss.com/jboss-server/jboss-as-7/jboss-as-7-remote-ejb-client-tutorial

【讨论】:

    猜你喜欢
    • 2011-04-20
    • 1970-01-01
    • 2011-03-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多