请高手指点
我用WEBLOGIC8.1容器,客户端调用EJB老是报这样的错,问题到底出在哪里?
Caught exception!
javax.naming.NameNotFoundException: Unable to resolve 'AccountHome' Resolved ; remaining name 'AccountHome'
at weblogic.rjvm.BasicOutboundRequest.sendReceive(BasicOutboundRequest.java:108)
at weblogic.rmi.cluster.ReplicaAwareRemoteRef.invoke(ReplicaAwareRemoteRef.java:284)
at weblogic.rmi.cluster.ReplicaAwareRemoteRef.invoke(ReplicaAwareRemoteRef.java:244)
at weblogic.jndi.internal.ServerNamingNode_812_WLStub.lookup(Unknown Source)
at weblogic.jndi.internal.WLContextImpl.lookup(WLContextImpl.java:343)
at weblogic.jndi.internal.WLContextImpl.lookup(WLContextImpl.java:336)
at javax.naming.InitialContext.lookup(InitialContext.java:347)
at com.xinguo.spdm.logic.AccountClient.main(AccountClient.java:53)
Caused by: javax.naming.NameNotFoundException: Unable to resolve 'AccountHome' Resolved
at weblogic.jndi.internal.BasicNamingNode.newNameNotFoundException(BasicNamingNode.java:858)
at weblogic.jndi.internal.BasicNamingNode.lookupHere(BasicNamingNode.java:230)
at weblogic.jndi.internal.ServerNamingNode.lookupHere(ServerNamingNode.java:154)
at weblogic.jndi.internal.BasicNamingNode.lookup(BasicNamingNode.java:188)
at weblogic.jndi.internal.RootNamingNode_WLSkel.invoke(Unknown Source)
at weblogic.rmi.internal.BasicServerRef.invoke(BasicServerRef.java:477)
at weblogic.rmi.cluster.ReplicaAwareServerRef.invoke(ReplicaAwareServerRef.java:108)
at weblogic.rmi.internal.BasicServerRef$1.run(BasicServerRef.java:420)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:353)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:144)
at weblogic.rmi.internal.BasicServerRef.handleRequest(BasicServerRef.java:415)
at weblogic.rmi.internal.BasicExecuteRequest.execute(BasicExecuteRequest.java:30)
at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:197)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:170)
Destroy account.
AccountClient.java
package com.xinguo.spdm.logic;
import java.util.Hashtable;
import java.util.Iterator;
import javax.naming.*
public class AccountClient {
private com.xinguo.spdm.logic.AccountHome getHome()
throws NamingException {
StringBuffer buffer = new StringBuffer();
return (com.xinguo.spdm.logic.AccountHome) getContext().lookup(
com.xinguo.spdm.logic.AccountHome.JNDI_NAME);
}
private InitialContext getContext() throws NamingException {
Hashtable props = new Hashtable();
props.put(
InitialContext.INITIAL_CONTEXT_FACTORY,
"weblogic.jndi.WLInitialContextFactory");
props.put(InitialContext.PROVIDER_URL, "t3://127.0.0.1:7001");
// This establishes the security for authorization/authentication
// props.put(InitialContext.SECURITY_PRINCIPAL,"username");
// props.put(InitialContext.SECURITY_CREDENTIALS,"password");
InitialContext initialContext = new InitialContext(props);
return initialContext;
}
public static void main(String[] args) {
AccountClient client = new AccountClient();
Account account = null;
try
{
Context ctx = client.getContext();
Object obj = ctx.lookup("AccountHome");
AccountHome Home = (AccountHome)PortableRemoteObject.narrow(obj,AccountHome.class);
System.err.println("Total of all accounts in bank initially ="+Home.getTotalBankValue());
Home.create("123-456-7890","John Smith");
Iterator i = Home.findByOwnerName("John Smith").iterator();
if(i.hasNext()){
account = (Account)PortableRemoteObject.narrow(i.next(),Account.class);
}
else{
throw new Exception("Could not find account");
}
System.out.println("Initial Balance ="+account.getBalance());
account.deposit(100);
System.out.println("After depositiong 100,account balance="+account.getBalance());
System.out.println("Total of all accounts in bank now="+Home.getTotalBankValue());
AccountPK pk = (AccountPK)account.getPrimaryKey();
account = null;
account = Home.findByPrimaryKey(pk);
System.out.println("Found account with ID"+pk+".Balance="+account.getBalance());
System.out.println("Now trying to withdraw $150,which is more than is currently available.This should generate an exception..");
account.withdraw(150);
}
catch(Exception e)
{
System.out.println("Caught exception!");
e.printStackTrace();
}
finally{
try
{
System.out.println("Destroy account.");
if(account!=null)
{
account.remove();
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
AccountClient test = new AccountClient();
}
}
配置文件
<?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 >
<description><![CDATA[No Description.]]></description>
<display-name>Generated by XDoclet</display-name>
<enterprise-beans>
<!-- Session Beans -->
<!--
To add session beans that you have deployment descriptor info for, add
a file to your XDoclet merge directory called session-beans.xml that contains
the <session></session> markup for those beans.
-->
<!-- Entity Beans -->
<entity >
<description><![CDATA[]]></description>
<ejb-name>Account</ejb-name>
<Home>com.xinguo.spdm.logic.AccountHome</Home>
<remote>com.xinguo.spdm.logic.Account</remote>
<local-home>com.xinguo.spdm.logic.AccountLocalHome</local-home>
<local>com.xinguo.spdm.logic.AccountLocal</local>
<ejb-class>com.xinguo.spdm.logic.AccountBMP</ejb-class>
<persistence-type>Bean</persistence-type>
<prim-key-class>com.xinguo.spdm.logic.AccountPK</prim-key-class>
<reentrant>False</reentrant>
</entity>
<!--
To add entity beans that you have deployment descriptor info for, add
a file to your XDoclet merge directory called entity-beans.xml that contains
the <entity></entity> markup for those beans.
-->
<!-- Message Driven Beans -->
<!--
To add message driven beans that you have deployment descriptor info for, add
a file to your XDoclet merge directory called message-driven-beans.xml that contains
the <message-driven></message-driven> markup for those beans.
-->
</enterprise-beans>
<!-- Relationships -->
<!-- Assembly Descriptor -->
<assembly-descriptor >
<!--
To add additional assembly descriptor info here, add a file to your
XDoclet merge directory called assembly-descriptor.xml that contains
the <assembly-descriptor></assembly-descriptor> markup.
-->
<!-- finder permissions -->
<!-- transactions -->
<!-- finder transactions -->
</assembly-descriptor>
</ejb-jar>
问题点数:20、回复次数:2Top
1 楼icebluenet(冰蓝泠)回复于 2004-07-01 15:40:28 得分 10
程序是不要看了,你到你的WEBLOGIC控制台去看看,'AccountHome' 是不是已经被部署了,
删掉已部署得,重新来Top
2 楼QJava(Echo)回复于 2004-07-01 15:47:38 得分 10
JNDI绑定的问题Top




