【问题标题】:JBoss 7: JNDI lookupJBoss 7:JNDI 查找
【发布时间】:2013-01-15 11:12:08
【问题描述】:

一段时间后,我远程访问了在 JBoss 7.1.1 下运行的无状态 EJB。使用属性对象:

Properties jndiProps = new Properties();
jndiProps.put(Context.INITIAL_CONTEXT_FACTORY, 
    "org.jboss.naming.remote.client.InitialContextFactory");
jndiProps.put(Context.PROVIDER_URL,"remote://localhost:4447");
jndiProps.put(Context.SECURITY_PRINCIPAL, "remote");
jndiProps.put(Context.SECURITY_CREDENTIALS, "remotepwd");
jndiProps.put("jboss.naming.client.ejb.context", true);
Context ctx = new InitialContext(jndiProps);

String lookupString = "//HelloWorld/HelloWorldBean!org.acme.test.HelloWorld";
HelloWorld hw = (HelloWorld) ctx.lookup(lookupString);
System.out.println("Response: "+ hw.sayHello("Hi there"));

所以这很好用,但现在我想将 JNDI 东西放入 jndi.properties 文件但失败了,文件如下所示:

java.naming.factory.initial=org.jboss.naming.remote.client.InitialContextFactory
java.naming.factory.url.pkgs=org.jboss.ejb.client.naming
java.naming.provider.url=remote://localhost:4447
java.naming.security.principal=remote
java.naming.security.credentials=remotepwd

例外:

Exception in thread "main" java.lang.IllegalStateException: No EJB receiver available for handling [appName:,modulename:HelloWorld,distinctname:] combination for invocation context org.jboss.ejb.client.EJBClientInvocationContext@108c175
at org.jboss.ejb.client.EJBClientContext.requireEJBReceiver(EJBClientContext.java:584)
at org.jboss.ejb.client.ReceiverInterceptor.handleInvocation(ReceiverInterceptor.java:119)
at org.jboss.ejb.client.EJBClientInvocationContext.sendRequest(EJBClientInvocationContext.java:181)
at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:136)
at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:121)
at org.jboss.ejb.client.EJBInvocationHandler.invoke(EJBInvocationHandler.java:104)
at $Proxy0.sayHello(Unknown Source)
at de.brockhaus.test.client.TestClient.main(TestClient.java:35)

我已经通过了几个doc但都失败了,那它应该是什么样子呢?

【问题讨论】:

    标签: jboss jndi


    【解决方案1】:

    好的,所以我自己找到了答案......

    首先你需要有两个属性文件,jndi.properties 和 jboss-ejb-client.properties。

    jndi.properties:

    #
    # jndi.properties
    #
    java.naming.factory.initial=org.jboss.naming.remote.client.InitialContextFactory
    java.naming.factory.url.pkgs=org.jboss.ejb.client.naming
    java.naming.provider.url=remote://localhost:4447
    java.naming.security.principal=remote
    java.naming.security.credentials=remotepwd
    

    jboss-ejb-client.properties:

    #
    # jboss-ejb-client.properties
    #
    remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED=false
    remote.connections=default
    remote.connection.default.host=localhost
    remote.connection.default.port = 4447
    remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS=false
    

    即使没有在代码中指定属性,将它们都放在类路径中也会使代码像魅力一样运行。

    仍然令人困惑的是查找字符串的构造...

    【讨论】:

    猜你喜欢
    • 2013-11-24
    • 1970-01-01
    • 2017-08-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-13
    • 2012-09-12
    相关资源
    最近更新 更多