异常信息:

08:02:56,329  WARN SessionFactoryObjectFactory:123 - Could not unbind factory from 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(NamingManager.java:645)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:325)
at javax.naming.InitialContext.unbind(InitialContext.java:416)
at org.hibernate.impl.SessionFactoryObjectFactory.removeInstance(SessionFactoryObjectFactory.java:116)
at org.hibernate.impl.SessionFactoryImpl.close(SessionFactoryImpl.java:806)
at org.hibernate.test.junit.UserTest.tearDown(UserTest.java:43)
at junit.framework.TestCase.runBare(TestCase.java:130)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

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

原来是Hibernate的配置文件hibernate.cfg.xml有问题

<hibernate-configuration>
<session-factory name="foo">
<property name="hibernate.connection.url">jdbc:oracle:thin:@10.240.144.25:1521:MES</property>
<property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="hibernate.connection.username">*****</property>
<property name="hibernate.connection.password">*****</property>
<property name="dialect">org.hibernate.dialect.OracleDialect</property>
<property name="show_sql">true</property> <mapping resource="org/hibernate/test/User.hbm.xml"/> </session-factory>
</hibernate-configuration>

原因:<seesion-factory>元素多了属性 name.

这样,hibernate会试图把这个sessionfacotry注册到JNDI中去

解决:去了name属性



Hibernate出现javax.naming.NoInitialContextException 错误的解决办法的更多相关文章

  1. javax.naming.NoInitialContextException错误的解决方案

    今天,学习用了一下nutz框架,写了一个HelloWorld的小程序,在用jndi配置数据源时,写了一个测试类,并在main方法中调用了jndi获得数据库连接,但是报错了,错误信息如下: javax. ...

  2. javax.naming.NoInitialContextException: Need to specify class name in environment or system property

    javax.naming.NoInitialContextException: Need to specify class name in environment or system property ...

  3. 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

    小弟初次用JNDI,使用数据源连接数据库,配置完相关的xml文件后,激动的我赶紧测试了一下,结果悲剧了,报出了错误: javax.naming.NoInitialContextException:Ne ...

  4. Oracle的常见错误及解决办法

    ORA-12528: TNS:listener: all appropriate instances are blocking new connections ORA-12528问题是因为监听中的服务 ...

  5. WIN7下安装visualC++2008 redistributable 出现1935错误的解决办法(转自)

    转自:http://zhidao.baidu.com/link?url=jylNh_JeANi4wrOMmd4d2i06e_N3QCw7z6BLGiNNNTu1Hc6ADTkUq2PORExKmjtk ...

  6. Oracle客户端工具出现“Cannot access NLS data files or invalid environment specified”错误的解决办法

    Oracle客户端工具出现"Cannot access NLS data files or invalid environment specified"错误的解决办法 方法一:参考 ...

  7. IOS 开发中 Whose view is not in the window hierarchy 错误的解决办法

    在 IOS 开发当中经常碰到 whose view is not in the window hierarchy 的错误,该错误简单的说,是由于 "ViewController" ...

  8. VS2010出现FileTracker : error FTK1011编译错误的解决办法

    VS2010出现FileTracker : error FTK1011不知道是不是vs2010的一个bug,反正有人提交了. FileTracker : error FTK1011编译错误的解决办法有 ...

  9. SQL SERVER数据库备份时出现“操作系统错误5(拒绝访问)。BACKUP DATABASE 正在异常终止。”错误的解决办法

    一般备份文件选择的目录为磁盘根目录或备份所选分区未授予sqlserver用户读写权限时会出现此错误. 解决办法就是给sqlserver用户授予权限: 选择要备份的文件夹 ,右键-->属性--&g ...

随机推荐

  1. Android数据的四种存储方式SharedPreferences、SQLite、Content Provider和File (一) —— 总览

    Android数据的四种存储方式SharedPreferences.SQLite.Content Provider和File (一) —— 总览   作为一个完成的应用程序,数据存储操作是必不可少的. ...

  2. android MVP模式介绍与实战

    android MVP模式介绍与实战 描述 MVP模式是什么?MVP 是从经典的模式MVC演变而来,它们的基本思想有相通的地方:Controller/Presenter负责逻辑的处理,Model提供数 ...

  3. JS中检测数据类型的几种方式及优缺点

    1.typeof 用来检测数据类型的运算符 typeof value 返回值首先是一个字符串,其次里面包含了对应的数据类型,例如:"number"."string&quo ...

  4. [经验][JS]如何观察网站,进而模仿

    应该存在着一类人: 1.看到美丽的网站时,就会F12,看看他是怎么实现的 2.看到网站数据是自己需要的时候,就会F12,看看他是怎么拿到数据的 3.看到网站一个有趣的模块时,,就会F12,看看他是怎么 ...

  5. android XMl 解析神奇xstream 三: 把复杂对象转换成 xml

    前言:对xstream不理解的请看: android XMl 解析神奇xstream 一: 解析android项目中 asset 文件夹 下的 aa.xml 文件 android XMl 解析神奇xs ...

  6. Xcode证书路径和缓存清理路径

    1.Xcode证书路径: ~/Library/MobileDevice/Provisioning Profiles 2.Jenkines共享证书路径: /用户/共享/Jenkins/Library/M ...

  7. 在Eclipse设置打开项目或文件目录

      Run-->External Tools-->Open External Tools Dialog... new 一个 program location 里面填 :C:\WINDOWS ...

  8. iOS循环引用问题

    今天面试问道了循环引用,所以就看了看,原来只是知道使用了Block容易造成循环引用.今天就来简单的介绍一些循环引用. 先来简单介绍一下什么是循环引用? 循环引用可以简单的理解成:A对象引用了B对象,B ...

  9. 简明 Vim 练级攻略(转)

    原文:http://coolshell.cn/articles/5426.html vim的学习曲线相当的大(参看各种文本编辑器的学习曲线),所以,如果你一开始看到的是一大堆VIM的命令分类,你一定会 ...

  10. OC的项目网址(自己编写的项目)

    因为便于方便快速打开自己曾经写过的项目,所以就把链接保存在博客里了.一点击就能找到. <附注学习github排版:https://github.com/yangxuanxc/guide?file ...