【发布时间】:2016-03-31 21:23:31
【问题描述】:
背景:我正在继承一个使用 EJB 的古老应用程序。在项目方面,它列为 3.0 EJB。 EJB 是在运行 WebSphere 6.1 时编写的,其中我们有两个 jvm,一个用于 UI/表示层,另一个 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 文件 A 包含一个名为 CHNew.war 的 .war,其中包含大部分前端逻辑,并且在部署程序集中引用了 CHService.jar 文件。名为 (CHService.ear) 的 Ear 文件 B 在名为 CHService.war 的 war 项目中包含 EJB 代码。它们都驻留在同一个应用服务器上,因此是同一个 jvm,但显然没有打包在同一个 ear 文件中。
耳朵A有如下web.xml sn-p:
<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 命名空间来引用两个 EJB(在同一个 EJB 应用程序中)具有以下 JNDI 名称(它们都引发了 JNDI 命名异常):
- java:global/CHServiceEAR/CHService/CHServiceBean!com.xxx.xxx.service.CHSerivceBean
- java:global/CHServiceEAR/CHService/CHServiceBean
【问题讨论】:
-
部署 EAR 时,Websphere 不会将 JNDI 上下文打印到服务器控制台或日志文件?
-
我在 Liberty 的一个开发环境中,你基本上放下耳朵(或使用添加/删除应用程序)然后 Liberty 加载它们。据我所见,它不会将名称空间转储到日志中。我在 server.xml 中添加了以下内容以启用 jndi 跟踪:
标签: jakarta-ee ejb websphere-liberty