尝试在 WebSphere Liberty 8.5.5.8 中绑定 EJB 时出错
Error Attempting to Bind EJB in WebSphere Liberty 8.5.5.8
背景:我继承了一个使用 EJB 的古老应用程序。在项目的方面,它列为 3.0 EJB。 EJB 是在 运行 WebSphere 6.1 时编写的,其中我们有两个 jvm,一个用于 UI/Presentation 层,另一个托管 EJB / "data layer" 的 JVM 也使用 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 文件,Ear 文件 A 名为 (CHNew.ear),其中包含一个名为 CHNew.war 的 .war,其中包含大部分前端逻辑和部署程序集引用 CHService.jar 文件。名为 (CHService.ear) 的耳文件 B 将 EJB 代码存放在名为 CHService.war 的 war 项目中。它们都驻留在同一个应用程序服务器上,因此也驻留在同一个 jvm 上,但显然没有打包在同一个 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>
问题:
- 我还需要做什么来绑定这个 EJB?
- 我已经尝试使用 java:global 命名空间来引用具有以下 JNDI 名称(都抛出 JNDI 命名异常)的两个 EJB(在同一个 EJB 应用程序中):
- java:global/CHServiceEAR/CHService/CHServiceBean!com.xxx.xxx.service.CHSerivceBean
- java:global/CHServiceEAR/CHService/CHServiceBean
您已经展示了 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 主题的 "Naming" 部分。您需要将绑定名称更新为 java:global/CHService/CHService/CHServiceBean
之类的名称。请参阅 messages.log 中的 CNTR0167I 消息以了解要使用的确切字符串。
背景:我继承了一个使用 EJB 的古老应用程序。在项目的方面,它列为 3.0 EJB。 EJB 是在 运行 WebSphere 6.1 时编写的,其中我们有两个 jvm,一个用于 UI/Presentation 层,另一个托管 EJB / "data layer" 的 JVM 也使用 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 文件,Ear 文件 A 名为 (CHNew.ear),其中包含一个名为 CHNew.war 的 .war,其中包含大部分前端逻辑和部署程序集引用 CHService.jar 文件。名为 (CHService.ear) 的耳文件 B 将 EJB 代码存放在名为 CHService.war 的 war 项目中。它们都驻留在同一个应用程序服务器上,因此也驻留在同一个 jvm 上,但显然没有打包在同一个 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>
问题:
- 我还需要做什么来绑定这个 EJB?
- 我已经尝试使用 java:global 命名空间来引用具有以下 JNDI 名称(都抛出 JNDI 命名异常)的两个 EJB(在同一个 EJB 应用程序中):
- java:global/CHServiceEAR/CHService/CHServiceBean!com.xxx.xxx.service.CHSerivceBean
- java:global/CHServiceEAR/CHService/CHServiceBean
您已经展示了 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 主题的 "Naming" 部分。您需要将绑定名称更新为 java:global/CHService/CHService/CHServiceBean
之类的名称。请参阅 messages.log 中的 CNTR0167I 消息以了解要使用的确切字符串。