WebSphere Liberty 18.0.0.3远程EJB查找失败

时间:2019-03-15 05:39:07

标签: java ejb javabeans ejb-3.1

WebSphere Liberty 8.0.0.3 EJB查找失败:

我使用以下代码创建了一个EJB,并将其部署在WebSphere Liberty 8.0.0.3。中。

ITestEJBRemoteInterface.java

package ejb31.test;

import javax.ejb.EJB;
import javax.ejb.Remote;

@Remote
@EJB(name="ejb/checkName")
public interface ITestEJBRemoteInterface
{ 
    public boolean checkNames(String fsName);
}

TestEJB.java:

package ejb31.test;
import java.util.Arrays;
import java.util.List;

import javax.ejb.EJB;
import javax.ejb.LocalBean;
import javax.ejb.Remote;
import javax.ejb.Stateless;
/** * Session Bean implementation class TestEJB */ 
@Stateless
@EJB(name="ejb/checkName")
public class TestEJB implements ITestEJBRemoteInterface 
{
    List<String> moListOfNames = Arrays.asList("Kevin","Jiten","Martina","Brian"); 
    /** * Default constructor. */
    public TestEJB() 
    { 

    } 
    /** * Find if the passed name is present in the default list of names 
     * 
     * 
     * 
     * @return */ 
    public boolean checkNames(String fsName)
    { 
        boolean lboolNamePresent = false; 
        if(fsName != null) 
        { 
            lboolNamePresent = moListOfNames.contains(fsName); 
        } 
        return lboolNamePresent; 
    }
}

ejb-jar.xml

<?xml version="1.0" encoding="UTF-8"?>
 <ejb-jar xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:ejb="http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_1.xsd" version="3.1"> 
 <display-name> TestEJB3.1 </display-name> 
 </ejb-jar>

EJB部署成功,并且日志文件抛出了绑定位置:

java:global / TestEJB3.1EAR / TestEJB3.1 / TestEJB!ejb31.test.ITestEJBRemoteInterface

问题在于调用ejb时。 WebSphereClient.java

package com.client;

import java.util.Properties;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

public class WebSphereClient {
    public static void main(String[] args) {

        String jndiPath = "corbaname:rir:#ejb/global/TestEJB3.1EAR/TestEJB3.1/TestEJB!ejb31.test.ITestEJBRemoteInterface";
        String provider = "corbaname:iiop:localhost:2809";

        Properties jndiLookupProps = new Properties();
        jndiLookupProps.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY,
         com.ibm.websphere.naming.PROPS.INITIAL_CONTEXT_FACTORY);
        jndiLookupProps.put(javax.naming.Context.PROVIDER_URL, provider);
        try {
            Object found = new InitialContext().lookup(jndiPath);
        } catch (NamingException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
    }
}

它抛出一个错误: javax.naming.InvalidNameException:名称组件“ TestEJB!ejb31.test.ITestEJBRemoteInterface”违反了INS名称语法。有多个未转义的ID /种类分隔符(“。”)。

当我尝试转义jndiPath时:

jndiPath = "corbaname:rir:#ejb/global/TestEJB3%5c.1EAR/TestEJB3%5c.1/TestEJB!ejb31%5c.test%5c.ITestEJBRemoteInterface";

jndiPath = "corbaname:rir:#ejb/global/TestEJB3\.1EAR/TestEJB3\.1/TestEJB!ejb31\.test\.ITestEJBRemoteInterface";

jndiPath = "corbaname:rir:#ejb/global/TestEJB3\\.1EAR/TestEJB3\\.1/TestEJB!ejb31\\.test\\.ITestEJBRemoteInterface";

它给出相同的错误。 如何使用远程客户端正确调用部署在Websphere自由中的EJB?

0 个答案:

没有答案
相关问题