Hibernate出现javax.naming.NoInitialContextException 错误的解决办法

异常信息如下:

initializing class SessionFactoryObjectFactory

registered: 8ad09e09444e60d001444e60d1820000 (foo)
Factory name: foo
JNDI InitialContext properties:{}
Could not bind factory to JNDI

javax.naming.NoInitialContextException: 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 javax.naming.spi.NamingManager.getInitialContext(Unknown Source)
at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(Unknown Source)
at javax.naming.InitialContext.getNameParser(Unknown Source)
at org.hibernate.util.NamingHelper.bind(NamingHelper.java:75)
at org.hibernate.impl.SessionFactoryObjectFactory.addInstance(SessionFactoryObjectFactory.java:113)
at org.hibernate.impl.SessionFactoryImpl.(SessionFactoryImpl.java:348)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1341)
at com.fh.util.HibernateUtil.buildSessionFactory(HibernateUtil.java:12)
at com.fh.util.HibernateUtil.(HibernateUtil.java:7)

at com.fh.test.StudentTest.main(StudentTest.java:13)

很奇怪抛出JNDI相关的异常信息,但是项目中并没有用到。

红色字体部分试图把SessionFactory foo 注册到JNDI中

恍然大悟,hibernate.cfg.xml文件 粘贴复制导致的此异常

Hibernate出现javax.naming.NoInitialContextException 错误的解决办法_第1张图片


你可能感兴趣的:(hibernate)