2013-01-15 42 views
6

经过了一段时间,我在远程访问了JBoss 7.1.1下的无状态EJB运行。使用Properties对象:JBoss 7:JNDI查找

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 [email protected] 
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但失败了,所以它是如何看起来像那么?

回答

7

好了,我发现自己的答案...

首先你需要有属性文件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 

在类路径中两者都会使代码的运行就像一个魅力,即使没有指定的属性在代码中。

仍扑朔迷离是查找字符串的建设...

+0

对于建设查找字符串,你可以参考这里:https://docs.jboss.org/author/display/AS72/Remote+EJB+调用+通过JNDI + + - + EJB +客户端+ API +或+远程命名+项目。在jboss服务器启动时,对于远程连接,查找字符串通常在“java:jboss/exported /”之后 – dellgg