zoukankan      html  css  js  c++  java
  • Hibernate出现javax.naming.NoInitialContextException 错误的解决办法

    异常信息:
    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属性


  • 相关阅读:
    类的特殊获取方式——《Thinking in Java》随笔008
    方法排序规范——《Thinking in Java》随笔007
    权限修饰符(访问指示符)——《Thinking in Java》随笔006
    史上最强,万能类型:Object——《Thinking in Java》随笔005
    七天C#小结
    编译原理10 消除左递归
    编译原理9 DFA最小化,语法分析初步
    编译原理8 非确定的自动机NFA确定化为DFA
    编译原理7 正规式、正规文法与自动机
    编译原理6 正规文法与正规式
  • 原文地址:https://www.cnblogs.com/kiwifly/p/4435863.html
Copyright © 2011-2022 走看看