4

我正在尝试从现在的某个时间退出来解决这个问题,我正在使用 OSUSER api 进行简单的用户和组访问。它适用于 JDBC 提供程序(在 OsUser.xml 和 PropertySet.xml 中)

现在,当我尝试使用它时,com.opensymphony.user.provider.hibernate.HibernateCredentialsProvider它会显示错误:

  at net.sf.hibernate.HibernateException: Could not find datasource: Name jdbc2 is not bound in this Context
  at net.sf.hibernate.connection.DatasourceConnectionProvider.configure(DatasourceConnectionProvider.java:47)
  at net.sf.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:75)
  at net.sf.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:144)
  at net.sf.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:571)
  at com.opensymphony.user.provider.hibernate.dao.SessionManager.<init>(SessionManager.java:34)
  at com.opensymphony.user.provider.hibernate.impl.OSUserHibernateConfigurationProviderImpl.setupConfiguration(OSUserHibernateConfigurationProviderImpl.java:101)
  at com.opensymphony.user.provider.hibernate.HibernateBaseProvider.init(HibernateBaseProvider.java:83)
  at com.opensymphony.user.provider.hibernate.HibernateProfileProvider.init(HibernateProfileProvider.java:98)
  at com.opensymphony.user.util.ConfigLoader.addProvider(ConfigLoader.java:113)
  at com.opensymphony.user.util.ConfigLoader.access$100(ConfigLoader.java:39)
  at com.opensymphony.user.util.ConfigLoader$ConfigHandler.endElement(ConfigLoader.java:144)
  at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.endElement(AbstractSAXParser.java:606)
  at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanEndElement(XMLDocumentFragmentScannerImpl.java:1742)
  at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2900)
  at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:607)
  at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:489)
  at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:835)
  at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:764)
  at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:123)
  at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1210)
  at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:568)
  at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl.parse(SAXParserImpl.java:302)
  at javax.xml.parsers.SAXParser.parse(SAXParser.java:195)
  at com.opensymphony.user.util.ConfigLoader.load(ConfigLoader.java:61)
  at com.opensymphony.user.UserManager.<init>(UserManager.java:108)
  at com.opensymphony.user.UserManager.<init>(UserManager.java:60)
  at com.opensymphony.user.UserManager.getInstance(UserManager.java:127)
  at com.fhl.LoginPage$1.onSubmit(LoginPage.java:28)
  at org.apache.wicket.markup.html.form.Form$10.component(Form.java:1157)
  at org.apache.wicket.markup.html.form.Form$10.component(Form.java:1152)
  at org.apache.wicket.util.visit.Visits.visitPostOrderHelper(Visits.java:273)
  at org.apache.wicket.util.visit.Visits.visitPostOrder(Visits.java:244)
  at org.apache.wicket.markup.html.form.Form.delegateSubmit(Form.java:1150)
  at org.apache.wicket.markup.html.form.Form.process(Form.java:803)
  at org.apache.wicket.markup.html.form.Form.onFormSubmitted(Form.java:728)
  at org.apache.wicket.markup.html.form.Form.onFormSubmitted(Form.java:670)
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  at java.lang.reflect.Method.invoke(Method.java:601)
  at org.apache.wicket.RequestListenerInterface.internalInvoke(RequestListenerInterface.java:260)
  at org.apache.wicket.RequestListenerInterface.invoke(RequestListenerInterface.java:216)
  at org.apache.wicket.request.handler.ListenerInterfaceRequestHandler.invokeListener(ListenerInterfaceRequestHandler.java:179)
  at org.apache.wicket.request.handler.ListenerInterfaceRequestHandler.respond(ListenerInterfaceRequestHandler.java:165)
  at org.apache.wicket.request.cycle.RequestCycle$HandlerExecutor.respond(RequestCycle.java:719)
  at org.apache.wicket.request.RequestHandlerStack.execute(RequestHandlerStack.java:63)
  at org.apache.wicket.request.cycle.RequestCycle.processRequest(RequestCycle.java:210)
  at org.apache.wicket.request.cycle.RequestCycle.processRequestAndDetach(RequestCycle.java:253)
  at org.apache.wicket.protocol.http.WicketFilter.processRequest(WicketFilter.java:162)
  at org.apache.wicket.protocol.http.WicketFilter.doFilter(WicketFilter.java:218)
  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
  at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224)
  at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
  at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
  at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
  at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
  at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929)
  at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
  at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:405)
  at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:964)
  at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:515)
  at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:304)
  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
  at java.lang.Thread.run(Thread.java:722)

Caused by: javax.naming.NameNotFoundException: Name jdbc2 is not bound in this Context
  at org.apache.naming.NamingContext.lookup(NamingContext.java:803)
  at org.apache.naming.NamingContext.lookup(NamingContext.java:159)
  at org.apache.naming.SelectorContext.lookup(SelectorContext.java:158)
  at javax.naming.InitialContext.lookup(InitialContext.java:411)
  at net.sf.hibernate.connection.DatasourceConnectionProvider.configure(DatasourceConnectionProvider.java:43)

通过控制台,它似乎无法找到数据源,尽管我已将 hibernate.cfg.xml 添加到类路径中,奇怪的是相同的数据源适用于 JDBC 连接。

这是我的hibernate.cfg.xml

<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
    <session-factory>
        <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
        <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
        <property name="connection.url">jdbc:mysql://localhost/tmpDb2</property>
        <property name="connection.username">root</property>
        <property name="connection.password">fhl</property>

        <!-- Use the C3P0 connection pool. -->
        <property name="c3p0.min_size">3</property>
        <property name="c3p0.max_size">5</property>
        <property name="c3p0.timeout">1800</property>

        <!-- Disable second-level cache. -->
        <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
        <property name="cache.use_query_cache">false</property>
        <property name="cache.use_minimal_puts">false</property>
        <property name="max_fetch_depth">3</property>

        <!-- Print SQL to stdout. -->
        <property name="show_sql">true</property>
        <property name="format_sql">true</property>

        <!-- Drop and then re-create schema on SessionFactory build, for testing. -->
        <property name="hbm2ddl.auto">create</property>

        <!-- Bind the getCurrentSession() method to the thread. -->
        <property name="current_session_context_class">thread</property>

        <!-- Hibernate XML mapping files -->
        <mapping resource="org/MyClass.hbm.xml" />

        <!-- Hibernate Annotations (and package-info.java) <mapping package="org.mypackage"/> 
            <mapping class="org.MyClass/> -->
    </session-factory>
</hibernate-configuration>

请告诉我我缺少什么,因为我是冬眠新手...

提前致谢。

4

3 回答 3

5

终于克服了这个问题,之前

    <property name="connection.datasource">fhlabs</property>

    <property name="connection.datasource">java:comp/env/fhlabs</property>

现在工作正常..cheerz ..!

于 2013-07-16T10:11:09.703 回答
0

我认为您缺少 jdbc2 的数据源配置。

于 2013-07-15T12:42:12.690 回答
0

您的设置似乎不一致。一方面,您正在通过 hibernate.cfg.xml 创建本地数据源,但您的堆栈跟踪表明您的代码希望通过 JNDI 以“jdbc2”的名称提供数据源。

您首先需要确定是否使用本地/JNDI 数据源并相应地设置您的环境

于 2013-07-15T13:48:34.333 回答