2013-01-15 202 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