Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/359.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/maven/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Can';t在JBoss EAP6下通过JNDI查找EJB远程_Java_Maven_Jboss_Ejb 3.0_Jndi - Fatal编程技术网

Java Can';t在JBoss EAP6下通过JNDI查找EJB远程

Java Can';t在JBoss EAP6下通过JNDI查找EJB远程,java,maven,jboss,ejb-3.0,jndi,Java,Maven,Jboss,Ejb 3.0,Jndi,我试图在Jboss EAP6下查找EJB3。 我有一个名为serviceall的maven EJB项目,其中我有两个包(interface和Impl),还有一个名为ClientEJB的java项目。 这是一个接口及其实现的示例: @Remote public IClient{ void showClient(String name); } @Statless @Remote(IClient.Class) public ClientImpl(){ public void showClient(S

我试图在Jboss EAP6下查找EJB3。 我有一个名为serviceall的maven EJB项目,其中我有两个包(interfaceImpl),还有一个名为ClientEJB的java项目。 这是一个接口及其实现的示例:

@Remote
public IClient{
void showClient(String name);
}
@Statless
@Remote(IClient.Class)
public ClientImpl(){
public void showClient(String name){
System.out.println("I'am Mr or Mme"+name);
}
实施:

@Remote
public IClient{
void showClient(String name);
}
@Statless
@Remote(IClient.Class)
public ClientImpl(){
public void showClient(String name){
System.out.println("I'am Mr or Mme"+name);
}
关于java项目,这是主类:

public MyClass{

  private IClient client;

  public static void main(String args[]){
    InvockClient().showClient("ClientTest");
  }

  public static IClient InvockClient(){
    final Hashtable jndiProperties = new Hashtable();
      jndiProperties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
      jndiProperties.put("jboss.naming.client.ejb.context", true);
      Context context;
      IClient client= null;
      try {
          context = new InitialContext(jndiProperties);
      client=(IUpdateCleRepartition) context.lookup("ejb:service-All/service-All /"+Client.class.getSimpleName()+"!" + IClient.class.getName());
          context.close();
      } catch (NamingException e) {
          System.out.println(e.getMessage());
      }
      return client;
  }
}
这是jboss-ejb-client.properties,我把它放在src\main\resources中

# JBoss, Home of Professional Open Source
# Copyright 2012, Red Hat, Inc. and/or its affiliates, and individual
# contributors by the @authors tag. See the copyright.txt in the 
# distribution for a full listing of individual contributors.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
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
service-All.jar部署在jboss EAP6上,当我运行main方法时,它给出以下信息:

log4j:WARN No appenders could be found for logger (org.jboss.logging).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
java.lang.IllegalStateException: EJBCLIENT000025: No EJB receiver available for handling [appName:serviceAll, moduleName:serviceAll, distinctName:] combination for invocation context org.jboss.ejb.client.EJBClientInvocationContext@1629bc56
at org.jboss.ejb.client.EJBClientContext.requireEJBReceiver(EJBClientContext.java:749)
at org.jboss.ejb.client.ReceiverInterceptor.handleInvocation(ReceiverInterceptor.java:116)
at org.jboss.ejb.client.EJBClientInvocationContext.sendRequest(EJBClientInvocationContext.java:186)
at org.jboss.ejb.client.EJBInvocationHandler.sendRequestWithPossibleRetries(EJBInvocationHandler.java:253)
at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:198)
at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:181)
at org.jboss.ejb.client.EJBInvocationHandler.invoke(EJBInvocationHandler.java:144)
at com.sun.proxy.$Proxy0.ShowClient(Unknown Source)
at org.kaml.MyClass.showClient(MyClass.java:12)
at eu.spb.batch.lceb.Launcher.main(MyClass.java:10)

有没有办法解决这个问题

我相信正确的jndi字符串应该是

ejb:/service-All/"+Client.class.getSimpleName()+"!" + IClient.class.getName()
ejb:/service-All/"+Client.class.getSimpleName()+"!" + IClient.class.getName()
您第一次出现的“全部服务”不属于您,因为您没有将ejb打包到ear中

另外,不要忘记在属性中传递用户名和密码

jndiProps.put(Context.SECURITY_PRINCIPAL, "peter");
jndiProps.put(Context.SECURITY_CREDENTIALS, "lois");
请记住,您必须将用户(本例中为“peter”)添加到jboss中。jboss-eap-6.0/bin/add-user.sh(或windows的add-user.bat)中有一个脚本

在这里您可以找到远程查找的文档


我的分数不允许我添加评论,所以我正在写答案。除了@mendieta建议的内容之外,您还可以检查您的ejb(ejb:service All/service All)是否在boot.log中正确部署

如果要进行远程查找,则必须在jndi属性中传递Context.PROVIDER_URL。您可以阅读更多关于这方面的内容,这是正确的方法: