0

首先这是我在 StackOverflow 上的第一个问题,我是德国一家公司的实习生,所以我的英语有点破,我的知识可能有限。

我尝试远程连接到 Jboss 6.1.0 eap。我使用 Eclipse 作为 EJB 和 EAR 的 IDE,但我运行 Jboss 表单 cmd

我的 ejb3 定义如下所示:

package de.jack;

import javax.ejb.Remote;

@Remote
public interface TestServiceRemote {
    public void sayRemote();

}

package de.jack;

import javax.ejb.Stateless;

/**
 * Session Bean implementation class TestService
 */
@Stateless
public class TestService implements TestServiceRemote {

    public TestService() {  }

    public void sayRemote() {
        System.out.println("\n\nHello");
    }
}

生成 .ear 文件后,我将它们部署在 JBoss AS 中,一切正常,我可以在浏览器中的 localhost:9990 下查看它们并检查它们是否已部署

现在到我失败的部分 - 客户:

public static void main(String argv[]){

        Properties props = new Properties();
        props.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
        props.put(Context.PROVIDER_URL, "remote://localhost:4447");
        props.put(Context.SECURITY_PRINCIPAL, "jack");
        props.put(Context.SECURITY_CREDENTIALS, "katze");
        props.put("jboss.naming.client.ejb.context", true);
        // create a context passing these properties
        InitialContext context;
        Object test = null;
        try {
            context = new InitialContext(props);
        } catch (NamingException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            return;
        }

        try {
            test = 
                 context.lookup("ConnectorBean/TestService!de.jack.TestServiceRemote");
        } catch (NamingException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            return;
        }

运行时出现异常:

org.jboss.naming.remote.protocol.NamingIOException: Failed to lookup [Root exception is java.io.IOException: java.lang.ClassNotFoundException: de.jack.TestServiceRemote]
    at org.jboss.naming.remote.client.ClientUtil.namingException(ClientUtil.java:49)
    at org.jboss.naming.remote.protocol.v1.Protocol$1.execute(Protocol.java:104)
    at org.jboss.naming.remote.protocol.v1.RemoteNamingStoreV1.lookup(RemoteNamingStoreV1.java:95)
    at org.jboss.naming.remote.client.HaRemoteNamingStore$1.operation(HaRemoteNamingStore.java:245)
...

我不确定我到底做错了什么,一个原因可能是我在机器上没有管理员权限,或者我混淆了客户端的属性

对不起我的英语不好,我非常感谢任何帮助!

4

2 回答 2

0
  1. 修改 TestService 类

    @Stateless
    @Remote(TestServiceRemote.class)  
    public class TestService implements TestServiceRemote {
    
        public TestService() {  }
    
        public void sayRemote() {
            System.out.println("\n\nHello");
        }
    }
    
  2. 确保远程客户端具有 TestServiceRemote.class 的引用

  3. 更改查找 jndi 名称

      // The app name is the application name of the deployed EJBs. This is typically the ear name
    // without the .ear suffix. However, the application name could be overridden in the application.xml of the
    // EJB deployment on the server.
    // Since we haven't deployed the application as a .ear, the app name for us will be an empty string
    final String appName = "";
    // This is the module name of the deployed EJBs on the server. This is typically the jar name of the
    // EJB deployment, without the .jar suffix, but can be overridden via the ejb-jar.xml
    // In this example, we have deployed the EJBs in a jboss-as-ejb-remote-app.jar, so the module name is
    // jboss-as-ejb-remote-app
    final String moduleName = "jboss-as-ejb-remote-app";
    // AS7 allows each deployment to have an (optional) distinct name. We haven't specified a distinct name for
    // our EJB deployment, so this is an empty string
    final String distinctName = "";
    // The EJB name which by default is the simple class name of the bean implementation class
    final String beanName = TestService.class.getSimpleName();
    // the remote view fully qualified class name
    final String viewClassName = TestServiceRemote.class.getName();
    
    String jndiName= "ejb:" + appName + "/" + moduleName + "/" + distinctName + "/" + beanName + "!" + viewClassName;
    
    TestServiceRemote service = (TestServiceRemote)context.lookup(jndiName);
    

详情请参考:https ://docs.jboss.org/author/display/AS71/EJB+invocations+from+a+remote+client+using+JNDI

于 2013-10-11T08:17:24.790 回答
0

服务器日志应该显示 bean 的正确全局 JNDI 名称。它应该类似于 foo/EJB-NAME/remote。然后你需要在 context.lookup("ConnectorBean/TestService!de.jack.TestServiceRemote") 中改变它。

请检查 - http://docs.jboss.org/ejb3/docs/tutorial/1.0.7/html/JNDI_Bindings.html

于 2013-10-11T07:49:16.833 回答