Topic: DAO模式下连接sessionBean出错??求教

  Print this page

1.DAO模式下连接sessionBean出错??求教 Copy to clipboard
Posted by: neweagle
Posted on: 2004-06-28 17:08

有问题请教各位大侠
 我用的jbuilder9+weblogic8
在用DAO模式设计EJB时出现下面错误:

ejbtest.dao.BookDAOSysException: BookDAOFactory.getDAO: NamingException while getting DAO type:
Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
  at ejbtest.dao.BookDAOSessionBeanFactory.getDAO(BookDAOSessionBeanFactory.java:23)
  at ejbtest.javaben.TestDao.<init>(TestDao.java:29)
  at ejbtest.javaben.TestDao.main(TestDao.java:81)
java.lang.NullPointerException
  at ejbtest.javaben.TestDao.getAll(TestDao.java:39)
  at ejbtest.javaben.TestDao.main(TestDao.java:83)
java.lang.Exception: failure:null
  at ejbtest.javaben.TestDao.getAll(TestDao.java:42)
  at ejbtest.javaben.TestDao.main(TestDao.java:83)

BookDAOSessionBeanFactory.java:

import javax.naming.InitialContext;
import javax.naming.NamingException;
import java.util.Properties;
import javax.naming.Context;

/***/
public class BookDAOSessionBeanFactory {

public static String Book_DAO_CLASS="java:comp/env/param/BookDAOClass";
public BookDAOSessionBeanFactory() {
}
public static BookDAO getDAO() throws BookDAOSysException{
BookDAO bookDAO=null;

try{
//this connect sessionbean
InitialContext context = new InitialContext();
String className = (String)context.lookup(Book_DAO_CLASS);//"java:comp/env/param/BookDAOClass");
bookDAO = (BookDAO)Class.forName(className).newInstance();
}catch(NamingException nex){
throw new BookDAOSysException("BookDAOFactory.getDAO: NamingException while getting DAO type:\n"+nex.getMessage());
}catch(Exception ex){
throw new BookDAOSysException("BookDAOFactory.getDAO: Exception while getting DAO type:\n"+ex.getMessage());
}
return bookDAO;
}
}

BookDAO.java:


import java.sql.Exception;
/***/
public interface BookDAO {

//
public java.util.Collection getAll()throws Exception;
}

ejb-jar.xml中有配置:
          <env-entry>
<description />
<env-entry-name>param/BookDAOClass</env-entry-name>
<env-entry-type>java.lang.String</env-entry-type>
<env-entry-value>BookDAOImpl</env-entry-value>
   </env-entry>

当我用一个java类来测试时,就出现上面所说的Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
错误,而我在配置文件(ejb-jar.xml)中有如上面所示,搞了一天 还是没有找到,请各位大侠指教 谢谢

2.Re:DAO模式下连接sessionBean出错??求教 [Re: neweagle] Copy to clipboard
Posted by: neweagle
Posted on: 2004-06-28 17:36

这个我是参考petstore中的catalog部分写的,不知咋的哪里有问题 郁闷


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923