尝试在WebSphere Liberty 8.5.5.8中绑定EJB时出错

时间:2016-03-31 21:23:31

标签: java-ee ejb websphere-liberty

背景:我继承了一个利用EJB的古老应用程序。在项目的方面,它列为3.0 EJB。 EJB是在运行WebSphere 6.1时编写的,其中我们有两个jvms,一个用于UI / Presentation Layer,另一个JVM托管EJB /"数据层"这也是使用JPA。我们正在转向WebSphere Liberty 8.5.5.8,当我启动应用程序并访问它时,我得到以下异常:

....
Caused by: 
com.ibm.wsspi.injectionengine.InjectionException: CWNEN0030E: The server was unable to obtain an object instance for the java:comp/env/ejb/CHServiceBean reference.  The exception message was: CWNEN1003E: The server was unable to find the com.xxx.xxx.service.CHServiceRemote binding with the com.xxx.xxx.service.CHService type for the java:comp/env/ejb/CHServiceBean reference.
    at com.ibm.wsspi.injectionengine.InjectionBinding.getInjectionObject(InjectionBinding.java:1458)
    at com.ibm.ws.ejb.injection.processor.EJBInjectionBinding.getInjectionObject(EJBInjectionBinding.java:1047)
    at com.ibm.wsspi.injectionengine.InjectionBinding.getInjectionObject(InjectionBinding.java:1389)
    at com.ibm.ws.injectionengine.osgi.internal.naming.InjectionJavaColonHelper.getObjectInstance(InjectionJavaColonHelper.java:116)
    ... 44 more
Caused by: 
com.ibm.wsspi.injectionengine.InjectionException: CWNEN1003E: The server was unable to find the com.xxx.xxxx.service.CHServiceRemote binding with the com.xxx.xxxxx.service.CHService type for the java:comp/env/ejb/CHServiceBean reference.
    at com.ibm.ws.injectionengine.osgi.internal.IndirectJndiLookupObjectFactory.getObjectInstance(IndirectJndiLookupObjectFactory.java:202)

以下是访问上下文对象的代码: 提供的失败的String jndiName是: "的java:comp / env的/ EJB / CHServiceBean"

public Object getResource(String jndiName) throws Exception {
    Object obj = null;
    if (obj == null) {
        try {
            obj = new InitialContext().lookup(jndiName);
            return obj;
        } catch (Exception e) {
            XXXXXX.error("ServiceLocator.getResource(...) ERROR, "");
            throw e;
        }
    }
    return obj;
}

我们有两个打包的EAR文件,名为(CHNew.ear)的Ear文件,其中包含一个名为CHNew.war的.war,它包含大部分前端逻辑,在部署程序集中引用了CHService.jar文件。调用的Ear文件B(CHService.ear)将EJB代码存放在名为CHService.war的war项目中。它们都驻留在同一个应用程序服务器上,因此是相同的jvm,但显然没有打包在同一个ear文件中。

Ear A有以下web.xml片段:

<ejb-ref id="EjbRef_1430884948507">
  <description>
  </description>
  <ejb-ref-name>ejb/CHServiceBean</ejb-ref-name>
  <ejb-ref-type>Session</ejb-ref-type>
  <home>com.xxx.xxx.service.CHService</home>
  <remote>com.xxx.xxx.service.CHServiceRemote</remote>
</ejb-ref>
<ejb-ref id="EjbRef_1430885115133">
  <ejb-ref-name>ejb/CHServiceBeanRO</ejb-ref-name>
  <ejb-ref-type>Session</ejb-ref-type>
  <home>com.xxx.xxxx.service.CHServiceRO</home>
  <remote>com.xxx.xxx.service.CHServiceRemoteRO</remote>
</ejb-ref>

编辑:以下是ibm-web-bnx.xml文件的内容:

<?xml version="1.0" encoding="UTF-8"?>
<webappbnd:WebAppBinding xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:webappbnd="webappbnd.xmi" xmi:id="WebAppBinding_1430419801447" virtualHostName="default_host">
  <webapp href="WEB-INF/web.xml#WebApp_ID"/>
  <resRefBindings xmi:id="ResourceRefBinding_1430749102271" jndiName="services/cache/CHContacts">
    <bindingResourceRef href="WEB-INF/web.xml#ResourceRef_1430749102271"/>
  </resRefBindings>
  <resRefBindings xmi:id="ResourceRefBinding_1436377001246" jndiName="jdbc/nextgen">
    <bindingResourceRef href="WEB-INF/web.xml#ResourceRef_1436377001246"/>
  </resRefBindings>
  <resRefBindings xmi:id="ResourceRefBinding_1436377001247" jndiName="jdbc/nextgen_RO">
    <bindingResourceRef href="WEB-INF/web.xml#ResourceRef_1436377001247"/>
  </resRefBindings>
  <resRefBindings xmi:id="ResourceRefBinding_1456409466488" jndiName="services/cache/CHGeneric">
    <bindingResourceRef href="WEB-INF/web.xml#ResourceRef_1456409466488"/>
  </resRefBindings>
  <ejbRefBindings xmi:id="EjbRefBinding_1430884948507" jndiName="com.xxx.xxx.service.CHServiceRemote">
    <bindingEjbRef href="WEB-INF/web.xml#EjbRef_1430884948507"/>
  </ejbRefBindings>
  <ejbRefBindings xmi:id="EjbRefBinding_1430885115133" jndiName="com.xxx.xxx.service.CHServiceRemoteRO">
    <bindingEjbRef href="WEB-INF/web.xml#EjbRef_1430885115133"/>
  </ejbRefBindings>
</webappbnd:WebAppBinding>

*过去有绑定的.xmi(注意不是.xml)文件我认为会被忽略吗?

在Ear App B中有一个包含以下节的ibm-ejb-jar-bnd.xml文件:

<session name="CHServiceBean">
  <resource-ref name="jdbc/db" binding-name="jdbc/db"></resource-ref>
  <resource-ref name="services/cache/CacheA" binding-name="services/cache/CHBluepages"></resource-ref>
  <resource-ref name="services/cache/CacheB" binding-name="services/cache/CHGeneric" ></resource-ref>
</session>

<session name="CHServiceBeanRO">
  <resource-ref name="jdbc/db_RO"
      binding-name="jdbc/db_RO">
  </resource-ref>
  <resource-ref name="jdbc/db" binding-name="jdbc/db"></resource-ref>
  <resource-ref name="services/cache/CHGeneric" binding-name="services/cache/CHGeneric"></resource-ref>
  <resource-ref name="services/cache/CacheA" binding-name="services/cache/CacheB"></resource-ref>
</session>

这是我的Liberty server.xml文件:

<!-- Enable features -->
    <featureManager>
        <feature>javaee-7.0</feature>
        <feature>localConnector-1.0</feature>
        <feature>distributedMap-1.0</feature>
        <feature>adminCenter-1.0</feature> 
        <feature>ssl-1.0</feature>
        <feature>usr:webCacheMonitor-1.0</feature>
        <feature>webCache-1.0</feature>
        <feature>ldapRegistry-3.0</feature>
    </featureManager>

    <!--  Admin Center Config Start -->
    <!-- To access this server from a remote client add a host attribute to the following element, e.g. host="*" -->
    <httpEndpoint host="*" httpPort="9080" httpsPort="9443" id="defaultHttpEndpoint"/>

    <keyStore id="defaultKeyStore" password="xxxxxx"/> 

    <basicRegistry id="basic"> 
          <user name="wpsadmin" password="xxxxxx"/> 
    </basicRegistry> 

    <administrator-role> 
      <user>wpsadmin</user>
    </administrator-role>

    <remoteFileAccess> 
       <writeDir>${server.config.dir}</writeDir> 
    </remoteFileAccess>

    <!-- Automatically expand WAR files and EAR files -->
    <applicationManager autoExpand="true"/>
    <applicationMonitor updateTrigger="mbean"/>

    <enterpriseApplication id="CHNewCHRDMEAR" location="CHNewCHRDMEAR.ear" name="CHNewCHRDMEAR">
        <application-bnd>
            <security-role name="AllAuthenticated">
                <special-subject type="ALL_AUTHENTICATED_USERS"/>
            </security-role>
        </application-bnd>
    </enterpriseApplication>
    <enterpriseApplication id="CHServiceEAR" location="CHServiceEAR.ear" name="CHServiceEAR"/>

    <!--  JAAS Authentication Alias (Global) Config -->
    <authData id="r4dba" password="{xor}MzhmJT06ajI=" user="r4dba"/>

    <!--  JDBC Driver and Datasource Config -->
    <library id="DB2JCC4Lib">
        <fileset dir="C:\DB2\Jars" includes="db2jcc4.jar db2jcc_license_cisuz.jar"/>
    </library>
</server>

问题:

  1. 我还需要做什么来绑定这个EJB?
  2. 我尝试使用java:global命名空间引用具有以下JNDI名称的两个EJB(在相同的EJB应用程序中)(所有这些都引发了JNDI命名异常):
    1. 的java:全球/ CHServiceEAR / CHService / CHServiceBean com.xxx.xxx.service.CHSerivceBean
    2. 的java:全球/ CHServiceEAR / CHService / CHServiceBean

1 个答案:

答案 0 :(得分:1)

您已经展示了ibm-ejb-jar-bnd.xml,但是您需要显示CHNew.war中的ibm-web-bnd.xml。错误消息表明您的绑定配置如下:

<ejb-ref name="ejb/CHServiceBean" binding-name="com.xxx.xxx.service.CHServiceRemote">

...或类似的东西,如果你使用的是ibm-web-bnd.xmi:

  <ejbRefBindings xmi:id="EjbRefBinding_1430884948507" jndiName="com.xxx.xxx.service.CHServiceRemote">
    <bindingEjbRef href="WEB-INF/web.xml#EjbRef_1430884948507"/>
  </ejbRefBindings>

Liberty概要文件仅将EJB绑定到java:命名空间,而不会绑定到默认命名空间(包括com.xxx.xxx.service.CHServiceRemote等名称),因此此查找将始终失败。请参阅知识中心中Using enterprise JavaBeans with remote interfaces on Liberty主题的“命名”部分。您需要将绑定名称更新为java:global/CHService/CHService/CHServiceBean之类的内容。请参阅messages.log中的CNTR0167I消息,以获取要使用的确切字符串。