我正在尝试在Jboss EAP6下查找EJB 3。 我有一个名为 service-All 的maven EJB项目,其中我有两个包(接口和 Impl ),我还有一个其他java项目女巫命名为 ClientEJB 。 这是一个界面及其实现的示例:
@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 prject,这是主要类:
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)
任何解决问题的想法!
答案 0 :(得分:0)
我相信你的正确的jndi字符串应该是
ejb:/service-All/"+Client.class.getSimpleName()+"!" + IClient.class.getName()
" service-All"你没有属于,因为你没有将你的ejb包装在耳边。
另外,请勿忘记在您的媒体资源中传递用户名和密码
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)中有一个脚本
您可以在此找到远程查找的文档
答案 1 :(得分:0)
我的分数不允许我添加评论所以我正在写答案。除了@mendieta建议你可以检查你的ejb(ejb:service-All / service-All)是否在boot.log中正确部署
如果要进行远程查找,则必须在jndi属性中传递Context.PROVIDER_URL。您可以阅读有关here
的更多信息答案 2 :(得分:0)
这是正确的方法:
ejb:/service-All/"+Client.class.getSimpleName()+"!" + IClient.class.getName()