---
title: "hibernate启动时的一个小问题"
author: "harry"
date: "2010-01-07T21:39:40Z"
tags: []
categories: ["企业架构"]
slug: "hibernate"
draft: false
lastmod: "2010-01-07T21:39:40Z"
id: 565295
url: "https://harry.iteye.com/blog/565295"
---

测试时报错但测试可正常运行

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 net.sf.hibernate.util.NamingHelper.bind(NamingHelper.java:52)  
at net.sf.hibernate.impl.SessionFactoryObjectFactory.addInstance(SessionFactoryObjectFactory.java:90)  
at net.sf.hibernate.impl.SessionFactoryImpl.&lt;init&gt;(SessionFactoryImpl.java:172)  
at net.sf.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:796)  
at TestMain.main(TestMain.java:22)

在hibernate.cfg.xml中session-factory设置了name属性,hibernate会试图把这个sessionfacotry注册到jndi中去  
将name属性去掉即可解决