[jboss-user] [EJB/JBoss] - PostConstruct loadClass fails when porting to JBoss 5

jcstaff do-not-reply at jboss.com
Sun Aug 17 18:29:07 EDT 2008


I am in the process of trying out the new JBoss 5.0CR1 with Java 5 and am running into some classpath/loading issues. All applications built, deployed, and tested successfully with a legacy instance of JBoss 4.2.2.GA just prior to running these tests, so I am sure the overall structure of the EAR/EJB is correct. Something appears different with the class loadClass() in JBoss 5 versus earlier versions.

My @PostConstruct has the following code

  |     @PostConstruct
  |     public void init() {
  |         log.warn("init(), daoClass=" + daoClassName);
  |         teller = new TellerImpl();
  | 
  |         try {
  |             //direct instantiation works
  |             AccountDAO dao = new xxx.jpa.JPAAccountDAO();
  |             log.warn("found:" + dao.getClass());
  |             //reflection approach no longer works 
  |             dao = (AccountDAO)Thread.currentThread()
  |                                                .getContextClassLoader()
  |                                                .loadClass(daoClassName)
  |                                                .newInstance();
  |             ((TellerImpl)teller).setAcctDAO(dao);
  |         }
  |         catch (Exception ex) {
  |             log.fatal("error loading dao class:" + daoClassName, ex);
  | ...
  |         }
  |     }
  | 

As shown by the following debug output, the direct instantiation (added to help debug this) works, but the reflection no longer works when I deploy to JBoss 5.0CR1 versus 4.x


  | WARN  [TellerEJB] init(), xxx.jpa.JPAAccountDAO
  | 
  | WARN  [TellerEJB] found:class xxx.jpa.JPAAccountDAO
  | FATAL [TellerEJB] error loading dao xxx.jpa.JPAAccountDAO
  | java.lang.ClassNotFoundException: xxx.jpa.JPAAccountDAO
  | 

thanks,
jim

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4170954#4170954

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4170954



More information about the jboss-user mailing list