无状态sessionbean调用现有的entitybean时将如何配置ejb-jar.xml和weblogic-ejb-jar.xml?(jb+wl开发)

GumPGZ 2004-10-18 04:58:08
开发环境是:jbuilder2005+weblogic 8.1

我现做了一个entitybean,并且成功开发和部署了,写了testclient也都没有问题,该entitybean名字叫做:CrabinBean。

现在我又做了一个sessionbean,叫做:TravelAgentBean,stateless,该bean的功能是调用CrabinBean,但是我遇到了一个麻烦,就是在部署的时候,如何把在TravelAgentBean的配置文件中建立其与CrabinBean的关系?我只在ejb-jar.xml中增加了如下内容:
<ejb-ref>
<ejb-ref-name>CarbinRemote</ejb-ref-name>
<ejb-ref-type>Entity</ejb-ref-type>
<home>carbin.CarbinRemoteHome</home>
<remote>carbin.CarbinRemote</remote>
</ejb-ref>
但是rebuild TravelAgentBean的时候,出现如下错误:
"TravelAgentBean.jar": [J2EE:160119]Appc is unable to process the file 'D:\MyWork\TravelAgentEJB\TravelAgentBean.jar.jar'. The following error occurred:

"TravelAgentBean.jar": In ejb-jar.xml, the EJB 'TravelAgentBean' contains an invalid ejb-ref 'CarbinRemote'. The ejb-ref must either have an ejb-link set or an ejb-reference-description must be added to the weblogic-ejb-jar.xml descriptor for this ejb-ref.

"TravelAgentBean.jar": at weblogic.ejb20.deployer.MBeanDeploymentInfoImpl.initializeEJBLinkJNDINames(MBeanDeploymentInfoImpl.java:267)

"TravelAgentBean.jar": at weblogic.ejb20.deployer.MBeanDeploymentInfoImpl.<init>(MBeanDeploymentInfoImpl.java:236)


...

我的CrabinBean是能成功运行的,现在TravelAgentBean要使用到CrabinBean,那么如何在TravelAgentBean配置,就是这样一个问题。

谢谢各位!
...全文
183 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
serf 2004-10-20
  • 打赏
  • 举报
回复
link那句不要,那句是引用同一包内的local接口的。位于同一ejb包,或同一个ear包(包含多个ejb,war包).你说的那句link...在那个配置向导中是一个下拉框。可用的link那里都能选择,否则就不能用,你添了也只会报错。

那么说你已经解决了。恭喜恭喜。
GumPGZ 2004-10-19
  • 打赏
  • 举报
回复
我的不是一个web应用,是两个ejb,是一个ejb调用远程的ejb。我增加了
<ejb-ref>
<ejb-ref-name>CarbinRemote</ejb-ref-name>
<ejb-ref-type>Entity</ejb-ref-type>
<home>carbin.CarbinRemoteHome</home>
<remote>carbin.CarbinRemote</remote>
<ejb-link>Carbin</ejb-link>
</ejb-ref>

但是部署的时候提示我
Deployment failed on Server myserver
weblogic.management.DeploymentException:
Exception:weblogic.management.ApplicationException: activate failed for TravelAgentBean
Module: TravelAgentBean Error: Exception activating module: EJBModule(TravelAgentBean,status=PREPARED)


Unable to deploy EJB: TravelAgentBean from TravelAgentBean.jar:

weblogic.deployment.EnvironmentException: [J2EE:160101]Error: The ejb-link 'Carbin' declared in the ejb-ref or ejb-local-ref 'CarbinRemote' in the application module 'TravelAgentBean.jar' could not be resolved. The target EJB for the ejb-ref could not be found. Please ensure the link is correct.

我现在糊涂了,到底能不能调用?如果能应该怎样写呢?
serf 2004-10-19
  • 打赏
  • 举报
回复
对不起,我说错了,应该是weblogic.xml,被你提问给误导了。同一包内可用本地接口(不是说home,是说local),非同一包内用远程接口。这是我的一个web 应用 ejb的示例中web模块内的weblogic.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE weblogic-web-app PUBLIC "-//BEA Systems, Inc.//DTD Web Application 8.1//EN" "http://www.bea.com/servers/wls810/dtd/weblogic810-web-jar.dtd"> //这个非常重要
<weblogic-web-app>
<reference-descriptor>
<ejb-reference-description>
<ejb-ref-name>ejb/EjbRef1</ejb-ref-name>
<jndi-name>TestEJB</jndi-name>
</ejb-reference-description>
</reference-descriptor>
<context-root>WebModule1</context-root>
</weblogic-web-app>

把本地的ejb/ejbref1映射到系统的TestEJB上了。不懂可以看//这个非常重要那行的那个dtd,文件。下载一个,仔细读读。
GumPGZ 2004-10-19
  • 打赏
  • 举报
回复
就是说,cmp的CrabinBean和sessionbean TravelAgentBean必须在一个工程中,统一build然后,部署?如果不这样就不能调用到么?

那么如果调用别人写的ejb是不是必须要加到自己的工程中?还是只把别人的编译好的jar比如CrabinBean.jar加入到该sessionbean TravelAgentBean得工程中?
yeshucheng 2004-10-19
  • 打赏
  • 举报
回复
做sessionBean的容器,自然会生成JNDI名称。
不在同一个工程?呵呵,是不是说错了
不在同一个工程不可能调的到
GumPGZ 2004-10-19
  • 打赏
  • 举报
回复
谢谢,但是还有问题啊,如果分不够还可以再加

to yeshucheng(叶澍成):
我的CrabinBean就是cmp的,现在CrabinBean和TravelAgentBean不在一个工程里,CrabinBean已经成功部署,并且知道他的jndi是CarbinRemote,现在要在TravelAgentBean里面调用它。您说的,“把你的TravelAgentBean也作成相应的托管”是什么意思?我的TravelAgentBean是无状态的sessionbean.

to serf():
weblogic-ejb-jar.xml中没有“ejb-ref-description”这一项,errors提示:element type "ejb-ref-description" must be declared.
我的weblogic-ejb-jar.xml内容如下,要在那里加“ejb-ref-description”?
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE weblogic-ejb-jar PUBLIC "-//BEA Systems, Inc.//DTD WebLogic 8.1.0 EJB//EN" "http://www.bea.com/servers/wls810/dtd/weblogic-ejb-jar.dtd">
<weblogic-ejb-jar>
<weblogic-enterprise-bean>
<ejb-name>TravelAgentBean</ejb-name>
<jndi-name>TravelAgentBean</jndi-name>
</weblogic-enterprise-bean>
</weblogic-ejb-jar>
serf 2004-10-19
  • 打赏
  • 举报
回复
我的mail: serf@sohu.com.
serf 2004-10-19
  • 打赏
  • 举报
回复
发个mail给我,我给你个例子吧。
GumPGZ 2004-10-19
  • 打赏
  • 举报
回复
现在终于找到解决的办法了,首先在ejb-jar.xml中加入<ejb-ref>,如下:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN" "http://java.sun.com/dtd/ejb-jar_2_0.dtd">
<ejb-jar>
<display-name>TravelAgentBean</display-name>
<enterprise-beans>
<session>
<ejb-name>TravelAgentBean</ejb-name>
<home>travelagentejb.TravelAgentHome</home>
<remote>travelagentejb.TravelAgent</remote>
<ejb-class>travelagentejb.TravelAgentBean</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
<ejb-ref>
<ejb-ref-name>ejb/Carbin</ejb-ref-name>
<ejb-ref-type>Entity</ejb-ref-type>
<home>carbin.CarbinRemoteHome</home>
<remote>carbin.CarbinRemote</remote>
<!--<ejb-link>../CarbinEJB/CarbinEJB.jar#Carbin</ejb-link>-->//这一行不知道要不要加上
</ejb-ref>
</session>
</enterprise-beans>
<assembly-descriptor>
<container-transaction>
<method>
<ejb-name>TravelAgentBean</ejb-name>
<method-name>*</method-name>
</method>
<trans-attribute>Required</trans-attribute>
</container-transaction>
</assembly-descriptor>
</ejb-jar>

然后在weblogic-ejb-jar.xml中加入 <reference-descriptor>,如下:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE weblogic-ejb-jar PUBLIC "-//BEA Systems, Inc.//DTD WebLogic 8.1.0 EJB//EN" "http://www.bea.com/servers/wls810/dtd/weblogic-ejb-jar.dtd">
<weblogic-ejb-jar>
<weblogic-enterprise-bean>
<ejb-name>TravelAgentBean</ejb-name>
<reference-descriptor>
<ejb-reference-description>
<ejb-ref-name>ejb/Carbin</ejb-ref-name>
<jndi-name>CarbinRemote</jndi-name>
</ejb-reference-description>
</reference-descriptor>
<jndi-name>TravelAgentBean</jndi-name>
</weblogic-enterprise-bean>
</weblogic-ejb-jar>

部署程中,但是test却出现错误,提示:
weblogic.utils.AssertionError: ***** ASSERTION FAILED *****[ Environment not found on thread ]
...
GumPGZ 2004-10-19
  • 打赏
  • 举报
回复
楼上说的应该怎么操作?我没有找到
只有create ejb和import ejb阿?import之后也不能给两个ejb建立联系阿?
fkpwolf 2004-10-19
  • 打赏
  • 举报
回复
引用用jbx有工具加的,在ejb design中可以找到.
serf 2004-10-18
  • 打赏
  • 举报
回复
weblogic-ejb-jar中要有ejb中定义的新jndi名称<ejb-ref-name>CarbinRemote</ejb-ref-name>到被引用的ejb 的jndi名字的映射。
<ejb-ref-description>
<ejb-ref-name>CarbinRemote</ejb-ref-name> //ejb-jar里面的那句
<jndi-name>你用外部test调用该ejb的jndi名称<jndi-name>
<ejb-ref-description>
快点结贴,我要拿来做第五条三角裤,还差1元了。
yeshucheng 2004-10-18
  • 打赏
  • 举报
回复
如果你是用jb来做的,完全可以必开手动方式来手写配置文件。
建议使用cmp来做容器管理,相应的把你的TravelAgentBean也作成相应的托管。至于说调用可以采用JNDI的方式来做

67,515

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧