javax.naming.NoInitialContextException 异常处理
在进行Hibernate测试时,抛出以下异常:
Could not bind factory to JNDI
javax.naming.NoInitialContextException:Needtospecifyclassnameinenvironmentorsystemproperty,orasanappletparameter,orinanapplicationresourcefile:java.naming.factory.initial
atjavax.naming.spi.NamingManager.getInitialContext(NamingManager.java:645)
atjavax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)
atjavax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:325)
atjavax.naming.InitialContext.getNameParser(InitialContext.java:480)
at org.hibernate.util.NamingHelper.bind(NamingHelper.java:52)解决:
<session-factory name="foo">
[……]
</session-factory>
去掉name属性。
存在name属性时,hibernate会试图把这个sessionfacotry注册到jndi中去,这样就出现了上面那样的错误!