ejb的client包括application、applet、jsp/servlet等等,也包括其他ejb。调用代码是一样的。
解决方案 »
- 关于 Invalid byte 1 of 1-byte UTF-8 sequence
- 项目经理无法解决 高手快进 真的很急 正在研发....... 急急急 很棘手的问题
- SSH框架搭建完成启动tomcat有错误!!!
- 一个关于acegi的超级难题!世上有谁能解决?
- double 转 byte[] 的问题
- http://www-900.ibm.com/developerWorks/cn/wsdd/techjournal/0110_wosnick/index.shtml 出错 求救!
- 为表决心,再开一帖:JSP连接Oracle9,请进来检分!
- EL表达式中含有<>怎么能正确显示出来?
- jdk1.7环境下开发的SSH项目部署到jdk1.6环境下
- HQL语句为什么有错啊
- jboss+Tomcat的问题
- 关于EJB调用 急!!!!!!!!
在调用bean的
<enterprise-beans>
<session(entity)>
//加入
<ejb-ref>
<ejb-ref-name/>(被调bean的JNDI Name)(形式为ejb/名)
<ejb-ref-type/>
<home/>
<remote/>
<ejb-link/>(被调bean的ejb-name)
</ejb-ref>
</session(entity)>
</enterprise-beans>
调用时用查找EJB的方法就行
(lookup("java:comp/env/ejb/名"));
还有,你要是使用weblogic作为服务器的话还要在weblogic-ejb-jar.xml
的
<weblogic-ejb-jar>
//加入
<weblogic-enterprise-bean>
<ejb-name/>
<jndi-name/>(注意与前面的一致)
</weblogic-wnterprise-bean>
<weblogic-enterprise-bean>
<ejb-name/>
<jndi-name/>(注意与前面的一致)
</weblogic-wnterprise-bean>(把包中的所有bean都要按此形式写上)
</weblogic-ejb-jar>
/**
* Look up the MusicLibrary bean's home interface using JNDI.
*/
private MusicLibraryHome lookupMusicLibraryHome()
throws NamingException
{
Context ctx = getInitialContext(); try {
Object home =
(MusicLibraryHome)ctx.lookup("MusicLibraryEJB.MusicLibraryHome");
return (MusicLibraryHome)PortableRemoteObject.narrow(
home,
MusicLibraryHome.class); } catch (NamingException ne) {
log("The client was unable to lookup the EJBHome. Please make sure " +
"that you have deployed the ejb with the JNDI name " +
"MusicLibraryEJB.MusicLibraryHome on the WebLogic server at "+url);
throw ne;
}
} /**
* Get an initial context into the JNDI tree.
*
* Java2 clients can use the jndi.properties file to set the
* INITIAL_CONTEXT_FACTORY and the PROVIDER_URL
* private Context getInitialContext() throws NamingException {
* return new InitialContext();
* }
*
*
* Using a Properties object will work on JDK 1.1.x and Java2
* clients
*/
private Context getInitialContext() throws NamingException { try {
// Get an InitialContext
Properties h = new Properties();
h.put(Context.INITIAL_CONTEXT_FACTORY,
"weblogic.jndi.WLInitialContextFactory");
h.put(Context.PROVIDER_URL, url);
if (user != null) {
log ("user: " + user);
h.put(Context.SECURITY_PRINCIPAL, user);
if (password == null)
password = "";
h.put(Context.SECURITY_CREDENTIALS, password);
}
return new InitialContext(h);
} catch (NamingException ne) {
log("We were unable to get a connection to the WebLogic server at "+url);
log("Please make sure that the server is running.");
throw ne;
}
}
2。创建实例:(一句话而已,但前面要写对)
MusicLibrary musicLib = musicLibraryHome.create();3。调用EJB的方法:
// Remove any old data from the database.
musicLib.removeRecordingsThatExist(recInfos);
musicLib.removeBandsThatExist(bandInfos); // Create the Bands in the Database
musicLib.addBands(bandInfos);
我想可以了吧! 你的JNDI name不要搞错