JBoss 7:JNDI查找 [英] JBoss 7: JNDI lookup

查看:115
本文介绍了JBoss 7:JNDI查找的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

after quite a while I made the remote access to a stateless EJB run under JBoss 7.1.1. using Properties object:

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文件中,但是失败了,这就是文件的样子:

So this works fine but now I want to put the JNDI thing into jndi.properties file but failed, this is how the file looks like:

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)

我已经经历了几次doco,但是失败了,那么它看起来如何?

I already went through several doco but failed, so how does it have to look like then?

推荐答案

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

OK, so I found the answer myself ...

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

First you need to have two properties files, jndi.properties plus jboss-ejb-client.properties.

jndi.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:

#
# 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

将它们都放在类路径上,即使在代码中未指定属性的情况下,代码也可以像符咒一样运行.

Having both of them on the classpath will make the code run like a charm even without specifying the properties within the code.

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

Still confusing is the construction of the lookup string ...

这篇关于JBoss 7:JNDI查找的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆