我正在處理涉及休眠的應用程序。在 無法加載類[oracle.jdbc.driver.Oracle驅動程序]:無法加載類[oracle.jdbc.driver.Oracle驅動程序]
org.hibernate.boot.registry.classloading.spi.ClassLoadingException: 當調用我的應用程序我得到這個例外 org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.classForName(ClassLoaderServiceImpl.java:245) 在 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl.loadDriverIfPossible(DriverManagerConnectionProviderImpl.java:200) 在 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProvi derImpl.buildCreator(DriverManagerConnectionProviderImpl.java:156) 在 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl.configure(DriverManagerConnectionProviderImpl.java:95) 在 org.hibernate.boot.registry.internal.StandardServiceRegistryImpl。 configureService(StandardServiceRegistryImpl.java:111) 在 org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:234) 在 org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:206) at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.buildJdbcConnectionAccess(JdbcServicesImpl.java:260) 在 org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:94) 在 org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:111) 在 有機.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:234) 在 org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:206) 在 org.hibernate.cfg.Configuration.buildTypeRegistrations (Configuration.java:1887) at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1845) 在 com.infy.EPP.resources.HibernateUtility.createSessionFactory(HibernateUtility.java:36) 在 com.infy.EPP.dao.BankLocationDAOImpl.getListOfBanks(BankLocationDAOImpl.java:27) 在 com.infy.EPP .business.service.BankLocationServiceImpl.getListOfBanks(BankLocationServiceImpl.java:20) 在 com.infy.EPP.web.managedbeans.BankLocationBean。(BankLocationBean.java:53) 在sun.reflect.NativeConstructorAccessorImpl.newInstance0(母語 方法)at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Del egating.ConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:408) at java.lang.Class.newInstance(Class.java:433)at com.sun.faces.mgbean。 BeanBuilder.newBeanInstance(BeanBuilder.java:186) at com.sun.faces.mgbean.BeanBuilder.build(BeanBuilder.java:100)at com.sun.faces.mgbean.BeanManager.createAndPush(BeanManager.java:409) 在com.sun.faces.mgbean.BeanManager.create(BeanManager.java:269)在 com.sun.faces.el.ManagedBeanELResolver.resolveBean(ManagedBeanELResolver.java:257) 在 融爲一體。sun.faces.el.ManagedBeanELResolver.getValue(ManagedBeanELResolver.java:117) 在 com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:176) 在 com.sun.faces.el.DemuxCompositeELResolver。 getValue(DemuxCompositeELResolver.java:203) at org.apache.el.parser.AstIdentifier.getValue(AstIdentifier.java:71) at org.apache.el.parser.AstValue.getValue(AstValue.java:160)at org.apache.el.parser.AstEqual.getValue(AstEqual.java:37)at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:184) at org.apache.jasper.el.JspValueExpression.getValue (JspValueExpression.java:106) at java x.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:194) at javax.faces.component.UIComponentBase.isRendered(UIComponentBase.java:457) at javax.faces.component.UIComponent.encodeAll(UIComponent.java :1850) at javax.faces.render.Renderer.encodeChildren(Renderer.java:176)at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:889) at javax.faces.component.UIComponent.encodeAll (UIComponent.java:1856) 在javax.faces.component.UIComponent.encodeAll(UIComponent.java:1859) 在 com.sun.faces.application.view.JspViewHandlingStrategy.doRenderView(JspViewHandlingStrategy.java:431) 在 com.sun.faces.applicati on.view.JspViewHandlingStrategy.renderView(JspViewHandlingStrategy.java:232) 在 com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:133) 在 com.sun.faces.lifecycle.RenderResponsePhase。執行(RenderResponsePhase.java:120) at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:219) at javax.faces.webapp.FacesServlet.service(FacesServlet.java:647)在 org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303) 在 org.apache.catalina.core.ApplicationFilterChain.doFilter (ApplicationFilterChain.java:208) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) 在 org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) 在 org.apache.catalina .core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) 在 com.infy.EPP.web.filter.AuthenticationFilter.doFilter(AuthenticationFilter.java:57) 在 org.apache.catalina.core.ApplicationFilterChain.internalDoFilter (ApplicationFilterChain.java:241) 在 org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) 在 org.apache.catalina.core.Sta ndardWrapperValve.invoke(StandardWrapperValve.java:220) 在 org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122) 在 org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java: 505) 在 org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170) 在 org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103) 在 org.apache .catalina.valves.AccessLogValve.invoke(AccessLogValve.java:957) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve。的java:116) 在 org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:423) 在 org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1079) 在 有機.apache.coyote.AbstractProtocol $ AbstractConnectionHandler.process(AbstractProtocol.java:620) 在 org.apache.tomcat.util.net.JIoEndpoint $ SocketProcessor.run(JIoEndpoint.java:318) 在 的java.util.concurrent .ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) 在 java.util.concurrent.ThreadPoolExecutor中的$ Worker.run(ThreadPoolExecutor.java:617) 在 org.apach e.tomcat.util.threads.TaskThread $ WrappingRunnable.run(TaskThread.java:61)
****>在java.lang.Thread.run(Thread.java:744)引起的:
拋出java.lang.ClassNotFoundException:無法加載請求的類: oracle.jdbc.driver.Oracle司機
org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl $ AggregatedClassLoader.fin dClass(ClassLoaderServiceImpl.java:230)
在java.lang.ClassLoader.loadClass(ClassLoader.java:424)在 java.lang.ClassLoader.loadClass(ClassLoader.java:357)在 java.lang中.Class.forName0(Native Method)at java.lang.Class.forName(Class.java:340)at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.classForName(ClassLoaderServiceImpl.java:242) 。 .. 72更多
這是hibernate.cfg.xml:
<!-- hibernate dialect -->
<property name="hibernate.dialect">org.hibernate.dialect.OracleDialect</property>
<property name="hibernate.connection.driver_class">oracle.jdbc.driver.Oracle Driver</property>
<property name="hibernate.connection.url">jdbc:oracle:thin:@localhost:1521:xe</property>
<property name="hibernate.connection.username">system</property>
<property name="hibernate.connection.password">oracle</property>
<property name="transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>
<!-- Automatic schema creation (begin) === -->
<property name="hibernate.hbm2ddl.auto">none</property>
<!-- Simple memory-only cache -->
<property name="hibernate.cache.provider_class">org.hibernate.cache.HashtableCacheProvider</property>
<!-- Enable Hibernate's automatic session context management -->
<property name="current_session_context_class">thread</property>
<!-- <property name="show_sql">true</property> -->
<mapping class="com.infy.EPP.entites.LoginEntity" />
</session-factory>
這是Hibernate工具文件:
public class HibernateUtility
{
private static final String CONFIGURATION_LOCATION = "com/infy/EPP/resources/hibernate.cfg.xml";
private static SessionFactory sessionFactory = null;
private static ServiceRegistry serviceRegistry;
public synchronized static SessionFactory createSessionFactory() {
if (sessionFactory == null)
{
try {
// Step1 : Loading the configuration details from
// hibernate.cfg.xml
Configuration configuration = new Configuration()
.configure(CONFIGURATION_LOCATION);
System.out.println("configuration in Utility=="+configuration); //---//syso1
// Step2 : Creating ServiceRegistry using the
// StandardServiceRegistryBuilder and Configuration defined in
// Step 1
serviceRegistry = new StandardServiceRegistryBuilder()
.applySettings(configuration.getProperties()).build();
System.out.println("serviceRegistry=="+serviceRegistry); ---//syso 2
// Step3 : Creating the SessionFactory using the Configuration
// and serviceRegistry.
sessionFactory = configuration
.buildSessionFactory(serviceRegistry);
System.out.println("sessionFactory==="+sessionFactory); ---//syso 3
}
catch (Exception e)
{
e.printStackTrace();
EppLogger.logError("HibernateUtility",
"createSessionFactory", e.getMessage());
}
}
return sessionFactory;
}
}
這是DAO類的方法,我調用它:
public Login authorize(Login to) throws Exception
{
LoginEntity le = null;
SessionFactory sessionFactory = null;
Session session = null;
Login login =null;
try {
sessionFactory = HibernateUtility.createSessionFactory();
session=sessionFactory.openSession();
session.beginTransaction();
le = (LoginEntity)session.get(LoginEntity.class, to.getUserId());
if (le != null)
{
login = new Login();
login.setPassword(le.getPassword());
login.setRole(le.getRole());
login.setStatus(le.getStatus());
login.setUserId(le.getUserId());
}
session.getTransaction().commit();
}
catch (PersistenceException exception) {
EppLogger.logError(this.getClass().getName(), "authorize",
exception.getMessage());
throw new Exception("DAO.TECHNICAL_ERROR");
}
catch (Exception e)
{
e.printStackTrace();
EppLogger.logError(this.getClass().getName(), "authorize", e.getMessage());
throw new Exception("DAO.TECHNICAL_ERROR");
}
finally
{
if(session!=null)
{
session.close();
sessionFactory.close();
}
}
return login;
}
我在lib文件夾下有ojdbc7。它仍然沒有工作。 我已經通過了幾個建議在classpath中添加ojdbc14的頁面。仍然沒有工作
更新: 我已經把一些syso語句在Hibernate Utility文件中。我獲得了前兩名的價值,但不是第三名。
去除異常改變的空間後,「未知的服務請求[org.hibernate.engine.jdbc.connections.spi.ConnectionProvider] 「 –
Hibernate doc說 - 你應該在應用程序的生命週期中創建一次會話工廠,並且只有在你退出 程序時纔會關閉它。 我建議你閱讀關於SessionFactory的更多內容以及如何/何時關閉它。 快速修復:刪除sessionFactory.close();來自世界各地的 程序 –
謝謝!我會通過它 –