尝试首次使用Spring MVC与Hibernate集成,出现505错误。

huangapple go评论95阅读模式
英文:

Trying Spring MVC with Hibernate integration for the first time, getting error 505

问题

I am using Eclipse IDE, using Spring MVC with Hibernate ORM. All the details along with the errors shown in the browser and console are also given below.

Error shown in the internal browser:

HTTP Status 500 – Internal Server Error

Type Exception Report

Message Servlet.init() for servlet [dispatcher] threw an exception

Description The server encountered an unexpected condition that prevented it from fulfilling the request.

Exception
javax.servlet.ServletException: Servlet.init() for servlet [dispatcher] threw an exception
	org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:543)
	org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81)
	org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:690)
	org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
	org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:615)
	org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
	org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:818)
	org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1627)
	org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
	java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
	java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
	org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	java.lang.Thread.run(Unknown Source)

Root Cause
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating a bean with name 'departmentController': Unsatisfied dependency expressed through the field 'dao'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating a bean with name 'departmentDao': Unsatisfied dependency expressed through the field 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating a bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/dispatcher-servlet.xml]: Invocation of init method failed; nested exception is org.hibernate.exception.GenericJDBCException: Unable to open the JDBC Connection for DDL execution

Root Cause
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating a bean with name 'departmentDao': Unsatisfied dependency expressed through the field 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating a bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/dispatcher-servlet.xml]: Invocation of init method failed; nested exception is org.hibernate.exception.GenericJDBCException: Unable to open the JDBC Connection for DDL execution

Root Cause
org.springframework.beans.factory.BeanCreationException: Error creating a bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/dispatcher-servlet.xml]: Invocation of init method failed; nested exception is org.hibernate.exception.GenericJDBCException: Unable to open the JDBC Connection for DDL execution

Error displayed in the console:

WARN: HHH000342: Could not obtain a connection to query metadata: Cannot load JDBC driver class 'oracle.jdbc.driver.OracleDriver'
Sep 01, 2020 3:40:54 PM org.hibernate.dialect.Dialect <init>
INFO: HHH000400: Using dialect: org.hibernate.dialect.Oracle10gDialect
Cannot load JDBC driver class 'oracle.jdbc.driver.OracleDriver'
java.lang.UnsupportedClassVersionError: oracle/jdbc/driver/OracleDriver has been compiled by a more recent version of the Java Runtime (class file version 54.0), this version of the Java Runtime only recognizes class file versions up to 52.0 (unable to load class [oracle.jdbc.driver.OracleDriver])
ERROR: Unable to obtain a JDBC Connection
org.apache.commons.dbcp.SQLNestedException: Cannot load JDBC driver class 'oracle.jdbc.driver.OracleDriver'
	at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1136)
	at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:880)
	at org.hibernate.engine.jdbc.connections.internal.DatasourceConnectionProviderImpl.getConnection(DatasourceConnectionProviderImpl.java:122)
	at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator$ConnectionProviderJdbcConnectionAccess.obtainConnection(JdbcEnvironmentInitiator.java:180)

(Note: The provided content has been cleaned and returned as requested, without any additional information or responses.)

英文:

I am using Eclipse IDE using Spring MVC with Hibernate orm. All the details along with the errors shown in browser and console are also given below

Error shown in internalbrowser

HTTP Status 500 – Internal Server Error


Type Exception Report

Message Servlet.init() for servlet [dispatcher] threw exception

Description The server encountered an unexpected condition that prevented it from fulfilling the request.

Exception
javax.servlet.ServletException: Servlet.init() for servlet [dispatcher] threw exception
	org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:543)
	org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81)
	org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:690)
	org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
	org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:615)
	org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
	org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:818)
	org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1627)
	org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
	java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
	java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
	org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	java.lang.Thread.run(Unknown Source)


Root Cause
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name &#39;departmentController&#39;: Unsatisfied dependency expressed through field &#39;dao&#39;; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name &#39;departmentDao&#39;: Unsatisfied dependency expressed through field &#39;sessionFactory&#39;; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name &#39;sessionFactory&#39; defined in ServletContext resource [/WEB-INF/dispatcher-servlet.xml]: Invocation of init method failed; nested exception is org.hibernate.exception.GenericJDBCException: Unable to open JDBC Connection for DDL execution
	
Root Cause
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name &#39;departmentDao&#39;: Unsatisfied dependency expressed through field &#39;sessionFactory&#39;; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name &#39;sessionFactory&#39; defined in ServletContext resource [/WEB-INF/dispatcher-servlet.xml]: Invocation of init method failed; nested exception is org.hibernate.exception.GenericJDBCException: Unable to open JDBC Connection for DDL execution
	
Root Cause
org.springframework.beans.factory.BeanCreationException: Error creating bean with name &#39;sessionFactory&#39; defined in ServletContext resource [/WEB-INF/dispatcher-servlet.xml]: Invocation of init method failed; nested exception is org.hibernate.exception.GenericJDBCException: Unable to open JDBC Connection for DDL execution
	

error displayed in console:

WARN: HHH000342: Could not obtain connection to query metadata : Cannot load JDBC driver class &#39;oracle.jdbc.driver.OracleDriver&#39;
Sep 01, 2020 3:40:54 PM org.hibernate.dialect.Dialect &lt;init&gt;
INFO: HHH000400: Using dialect: org.hibernate.dialect.Oracle10gDialect
Cannot load JDBC driver class &#39;oracle.jdbc.driver.OracleDriver&#39;
java.lang.UnsupportedClassVersionError: oracle/jdbc/driver/OracleDriver has been compiled by a more recent version of the Java Runtime (class file version 54.0), this version of the Java Runtime only recognizes class file versions up to 52.0 (unable to load class [oracle.jdbc.driver.OracleDriver])
ERROR: Unable obtain JDBC Connection
org.apache.commons.dbcp.SQLNestedException: Cannot load JDBC driver class &#39;oracle.jdbc.driver.OracleDriver&#39;
at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1136)
at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:880)
at org.hibernate.engine.jdbc.connections.internal.DatasourceConnectionProviderImpl.getConnection(DatasourceConnectionProviderImpl.java:122)
at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator$ConnectionProviderJdbcConnectionAccess.obtainConnection(JdbcEnvironmentInitiator.java:180)
Caused by: java.lang.UnsupportedClassVersionError: oracle/jdbc/driver/OracleDriver has been compiled by a more recent version of the Java Runtime (class file version 54.0), this version of the Java Runtime only recognizes class file versions up to 52.0 (unable to load class [oracle.jdbc.driver.OracleDriver])
at org.apache.catalina.loader.WebappClassLoaderBase.findClassInternal(WebappClassLoaderBase.java:2397)
at org.apache.catalina.loader.WebappClassLoaderBase.findClass(WebappClassLoaderBase.java:855)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1327)
Hibernate: drop table MYDept cascade constraints
framework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:702)
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:668)
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:716)
at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:591)
at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:530)
at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:170)
at javax.servlet.GenericServlet.init(GenericServlet.java:158)
Cannot load JDBC driver class &#39;oracle.jdbc.driver.OracleDriver&#39;
java.lang.UnsupportedClassVersionError: oracle/jdbc/driver/OracleDriver has been compiled by a more recent version of the Java Runtime (class file version 54.0), this version of the Java Runtime only recognizes class file versions up to 52.0 (unable to load class [oracle.jdbc.driver.OracleDriver])
at org.apache.catalina.loader.WebappClassLoaderBase.findClassInternal(WebappClassLoaderBase.java:2397)
at org.apache.catalina.loader.WebappClassLoaderBase.findClass(WebappClassLoaderBase.java:855)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1327)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1180)
Sep 01, 2020 3:40:55 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
ERROR: Cannot load JDBC driver class &#39;oracle.jdbc.driver.OracleDriver&#39;
Sep 01, 2020 3:40:55 PM org.springframework.context.support.AbstractApplicationContext refresh
WARNING: Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name &#39;departmentController&#39;: Unsatisfied dependency expressed through field &#39;dao&#39;; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name &#39;departmentDao&#39;: Unsatisfied dependency expressed through field &#39;sessionFactory&#39;; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name &#39;sessionFactory&#39; defined in ServletContext resource [/WEB-INF/dispatcher-servlet.xml]: Invocation of init method failed; nested exception is org.hibernate.exception.GenericJDBCException: Unable to open JDBC Connection for DDL execution
Sep 01, 2020 3:40:55 PM org.springframework.web.servlet.FrameworkServlet initServletBean
SEVERE: Context initialization failed
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name &#39;departmentController&#39;: Unsatisfied dependency expressed through field &#39;dao&#39;; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name &#39;departmentDao&#39;: Unsatisfied dependency expressed through field &#39;sessionFactory&#39;; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name &#39;sessionFactory&#39; defined in ServletContext resource [/WEB-INF/dispatcher-servlet.xml]: Invocation of init method failed; nested exception is org.hibernate.exception.GenericJDBCException: Unable to open JDBC Connection for DDL execution
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name &#39;departmentDao&#39;: Unsatisfied dependency expressed through field &#39;sessionFactory&#39;; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name &#39;sessionFactory&#39; defined in ServletContext resource [/WEB-INF/dispatcher-servlet.xml]: Invocation of init method failed; nested exception is org.hibernate.exception.GenericJDBCException: Unable to open JDBC Connection for DDL execution
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:639)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:116)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name &#39;sessionFactory&#39; defined in ServletContext resource [/WEB-INF/dispatcher-servlet.xml]: Invocation of init method failed; nested exception is org.hibernate.exception.GenericJDBCException: Unable to open JDBC Connection for DDL execution
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1803)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:595)
Caused by: org.apache.commons.dbcp.SQLNestedException: Cannot load JDBC driver class &#39;oracle.jdbc.driver.OracleDriver&#39;
at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1136)
at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:880)
Caused by: java.lang.UnsupportedClassVersionError: oracle/jdbc/driver/OracleDriver has been compiled by a more recent version of the Java Runtime (class file version 54.0), this version of the Java Runtime only recognizes class file versions up to 52.0 (unable to load class [oracle.jdbc.driver.OracleDriver])
Sep 01, 2020 3:40:55 PM org.apache.catalina.core.ApplicationContext log
SEVERE: StandardWrapper.Throwable
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name &#39;departmentController&#39;: Unsatisfied dependency expressed through field &#39;dao&#39;; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name &#39;departmentDao&#39;: Unsatisfied dependency expressed through field &#39;sessionFactory&#39;; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name &#39;sessionFactory&#39; defined in ServletContext resource [/WEB-INF/dispatcher-servlet.xml]: Invocation of init method failed; nested exception is org.hibernate.exception.GenericJDBCException: Unable to open JDBC Connection for DDL execution
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name &#39;departmentDao&#39;: Unsatisfied dependency expressed through field &#39;sessionFactory&#39;; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name &#39;sessionFactory&#39; defined in ServletContext resource [/WEB-INF/dispatcher-servlet.xml]: Invocation of init method failed; nested exception is org.hibernate.exception.GenericJDBCException: Unable to open JDBC Connection for DDL execution
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:639)
Caused by: org.apache.commons.dbcp.SQLNestedException: Cannot load JDBC driver class &#39;oracle.jdbc.driver.OracleDriver&#39;
at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1136)
at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:880)
Caused by: java.lang.UnsupportedClassVersionError: oracle/jdbc/driver/OracleDriver has been compiled by a more recent version of the Java Runtime (class file version 54.0), this version of the Java Runtime only recognizes class file versions up to 52.0 (unable to load class [oracle.jdbc.driver.OracleDriver])
at org.apache.catalina.loader.WebappClassLoaderBase.findClassInternal(WebappClassLoaderBase.java:2397)
Sep 01, 2020 3:40:55 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Allocate exception for servlet [dispatcher]
java.lang.UnsupportedClassVersionError: oracle/jdbc/driver/OracleDriver has been compiled by a more recent version of the Java Runtime (class file version 54.0), this version of the Java Runtime only recognizes class file versions up to 52.0 (unable to load class [oracle.jdbc.driver.OracleDriver])

index.jsp

&lt;html&gt;
&lt;body&gt;
&lt;h2&gt;Department Actions&lt;/h2&gt;
&lt;a href=&quot;PreInsertDepartment&quot;&gt;Insert Department&lt;/a&gt;
&lt;/body&gt;
&lt;/html&gt;

DepartmentController.java

package com.wipro.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import com.wipro.bean.Department;
import com.wipro.dao.DepartmentDao;
@Controller
public class DepartmentController {
@Autowired
DepartmentDao dao;
@RequestMapping(&quot;PreInsertDepartment&quot;)
public ModelAndView preInsert() {
Department department = new Department();
department.setDeptno(dao.getDepartmentId());
ModelAndView mv = new
ModelAndView(&quot;InsertDepartment&quot;,&quot;department&quot;,department);
return mv;
}
@RequestMapping(&quot;InsertDepartment&quot;)
public ModelAndView insertDepartment(@ModelAttribute(&quot;department&quot;) Department dept) {
ModelAndView mv = new ModelAndView(&quot;result&quot;,&quot;department&quot;,dept);
if(dao.insertDepatment(dept))
mv.addObject(&quot;msg&quot;, &quot;Inserted Successfully&quot;);
else
mv.addObject(&quot;msg&quot;, &quot;Insert Failed&quot;);
return mv;
}
}

Department.java

package com.wipro.bean;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table(name=&quot;MYDept&quot;)
public class Department {
@Id
private int deptno;
@Column(length = 10)
private String dname;
@Column(length = 10)
private String loc;
public Department() {
super();
// TODO Auto-generated constructor stub
}
public Department(int deptno, String dname, String loc) {
super();
this.deptno = deptno;
this.dname = dname;
this.loc = loc;
}
public int getDeptno() {
return deptno;
}
public void setDeptno(int deptno) {
this.deptno = deptno;
}
public String getDname() {
return dname;
}
public void setDname(String dname) {
this.dname = dname;
}
public String getLoc() {
return loc;
}
public void setLoc(String loc) {
this.loc = loc;
}
@Override
public String toString() {
return &quot;Department [deptno=&quot; + deptno + &quot;, dname=&quot; + dname + &quot;, loc=&quot; + loc + &quot;]&quot;;
}
}

DepartmentDao.java

package com.wipro.dao;
import java.util.List;
import javax.transaction.Transactional;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.query.Query;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate5.HibernateTemplate;
import org.springframework.stereotype.Repository;
import com.wipro.bean.Department;
@Repository
@Transactional
public class DepartmentDao {
@Autowired
SessionFactory sessionFactory;
@Autowired
HibernateTemplate hibernateTemplate;
public int getDepartmentId() {
int id=0;
Session session = sessionFactory.openSession();
Query&lt;Department&gt; qry = session.createQuery(&quot;Select max(d.deptno) from Department d&quot;);
List l=qry.list();
System.out.println(&quot;L value&quot;+l + &quot; : &quot; );
if(l!=null &amp;&amp; l.size()&gt;0)
{
Object b=l.get(0);
if(b!=null)
id=(Integer) b;
}
session.close();
return id+10;
}
public boolean insertDepatment(Department department) {
hibernateTemplate.persist(department);
return true;
}
}

dispatcher-servlet.xml

&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;beans xmlns=&quot;http://www.springframework.org/schema/beans&quot;
xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
xmlns:aop=&quot;http://www.springframework.org/schema/aop&quot;
xmlns:context=&quot;http://www.springframework.org/schema/context&quot;
xmlns:jee=&quot;http://www.springframework.org/schema/jee&quot;
xmlns:mvc=&quot;http://www.springframework.org/schema/mvc&quot;
xmlns:lang=&quot;http://www.springframework.org/schema/lang&quot;
xmlns:p=&quot;http://www.springframework.org/schema/p&quot;
xmlns:tx=&quot;http://www.springframework.org/schema/tx&quot;
xmlns:util=&quot;http://www.springframework.org/schema/util&quot;
xsi:schemaLocation=&quot;http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/jee
http://www.springframework.org/schema/jee/spring-jee.xsd
http://www.springframework.org/schema/lang
http://www.springframework.org/schema/lang/spring-lang.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util.xsd">
&lt;context:component-scan base-package=&quot;com.wipro&quot; /&gt;
&lt;context:annotation-config /&gt;
&lt;!-- Including the bean for View Resolver --&gt;
&lt;bean
class=&quot;org.springframework.web.servlet.view.InternalResourceViewResolver&quot;&gt;
&lt;property name=&quot;prefix&quot;&gt;
&lt;value&gt;/WEB-INF/views/&lt;/value&gt;
&lt;/property&gt;
&lt;property name=&quot;suffix&quot;&gt;
&lt;value&gt;.jsp&lt;/value&gt;
&lt;/property&gt;
&lt;/bean&gt;
&lt;bean id=&quot;dataSource&quot;
class=&quot;org.apache.commons.dbcp.BasicDataSource&quot; destroy-method=&quot;close&quot;&gt;
&lt;property name=&quot;driverClassName&quot;
value=&quot;oracle.jdbc.driver.OracleDriver&quot; /&gt;
&lt;property name=&quot;url&quot;
value=&quot;jdbc:oracle:thin:@localhost:1521:xe&quot; /&gt;
&lt;property name=&quot;username&quot; value=&quot;system&quot; /&gt;
&lt;property name=&quot;password&quot; value=&quot;oracle&quot; /&gt;
&lt;/bean&gt;
&lt;bean id=&quot;sessionFactory&quot;
class=&quot;org.springframework.orm.hibernate5.LocalSessionFactoryBean&quot;&gt;
&lt;property name=&quot;dataSource&quot; ref=&quot;dataSource&quot; /&gt;
&lt;property name=&quot;hibernateProperties&quot;&gt;
&lt;props&gt;
&lt;prop
key=&quot;hibernate.dialect&quot;&gt;org.hibernate.dialect.Oracle10gDialect&lt;/prop&gt;
&lt;prop key=&quot;hibernate.show_sql&quot;&gt;true&lt;/prop&gt;
&lt;prop key=&quot;hibernate.hbm2ddl.auto&quot;&gt;create&lt;/prop&gt;
&lt;/props&gt;
&lt;/property&gt;
&lt;property name=&quot;packagesToScan&quot; value=&quot;com.wipro.bean&quot; /&gt;
&lt;/bean&gt;
&lt;bean id=&quot;hibernateTemplate&quot;
class=&quot;org.springframework.orm.hibernate5.HibernateTemplate&quot;&gt;
&lt;property name=&quot;sessionFactory&quot; ref=&quot;sessionFactory&quot;&gt;&lt;/property&gt;
&lt;/bean&gt;
&lt;tx:annotation-driven /&gt;
&lt;bean id=&quot;transactionManager&quot;
class=&quot;org.springframework.orm.hibernate5.HibernateTransactionManager&quot;&gt;
&lt;property name=&quot;sessionFactory&quot; ref=&quot;sessionFactory&quot; /&gt;
&lt;/bean&gt;
&lt;/beans&gt;

InsertDepartment.jsp

&lt;%@ page language=&quot;java&quot; contentType=&quot;text/html; charset=ISO-8859-1&quot;
pageEncoding=&quot;ISO-8859-1&quot;%&gt;
&lt;%@ taglib uri=&quot;http://www.springframework.org/tags/form&quot; prefix=&quot;sp&quot; %&gt;
&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;
&lt;meta charset=&quot;ISO-8859-1&quot;&gt;
&lt;title&gt;Insert title here&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;sp:form action=&quot;InsertDepartment&quot; method=&quot;post&quot; modelAttribute=&quot;department&quot;&gt;
Enter Department No: &lt;sp:input path=&quot;deptno&quot; /&gt;
Enter Department Name : &lt;sp:input path=&quot;dname&quot;/&gt;
Enter Department Location : &lt;sp:input path=&quot;loc&quot; /&gt;
&lt;input type=&quot;submit&quot;/&gt;
&lt;/sp:form&gt;
&lt;/body&gt;
&lt;/html&gt;

result.jsp

&lt;%@ page language=&quot;java&quot; contentType=&quot;text/html; charset=ISO-8859-1&quot;
pageEncoding=&quot;ISO-8859-1&quot; isELIgnored=&quot;false&quot; %&gt;
&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;
&lt;meta charset=&quot;ISO-8859-1&quot;&gt;
&lt;title&gt;Insert title here&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
${msg}
Department [ ${department.deptno } , ${department.dname } , ${department.loc } ] 
&lt;/body&gt;
&lt;/html&gt;

pom.xml
The ojdbc dependency used installs the required ojdbc jar in maven dependencies ok.

&lt;project xmlns=&quot;http://maven.apache.org/POM/4.0.0&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
xsi:schemaLocation=&quot;http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd&quot;&gt;
&lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
&lt;groupId&gt;com.wipro&lt;/groupId&gt;
&lt;artifactId&gt;SpringMVCwithHibernate&lt;/artifactId&gt;
&lt;packaging&gt;war&lt;/packaging&gt;
&lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
&lt;name&gt;SpringMVCwithHibernate Maven Webapp&lt;/name&gt;
&lt;url&gt;http://maven.apache.org&lt;/url&gt;
&lt;dependencies&gt;
&lt;dependency&gt;
&lt;groupId&gt;junit&lt;/groupId&gt;
&lt;artifactId&gt;junit&lt;/artifactId&gt;
&lt;version&gt;3.8.1&lt;/version&gt;
&lt;scope&gt;test&lt;/scope&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.springframework&lt;/groupId&gt;
&lt;artifactId&gt;spring-context&lt;/artifactId&gt;
&lt;version&gt;5.2.1.RELEASE&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.springframework&lt;/groupId&gt;
&lt;artifactId&gt;spring-core&lt;/artifactId&gt;
&lt;version&gt;5.2.1.RELEASE&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.springframework&lt;/groupId&gt;
&lt;artifactId&gt;spring-web&lt;/artifactId&gt;
&lt;version&gt;5.2.1.RELEASE&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.springframework&lt;/groupId&gt;
&lt;artifactId&gt;spring-webmvc&lt;/artifactId&gt;
&lt;version&gt;5.2.1.RELEASE&lt;/version&gt;
&lt;/dependency&gt;
&lt;!-- dependencies required for Hibernate ORM Integration --&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.hibernate&lt;/groupId&gt;
&lt;artifactId&gt;hibernate-core&lt;/artifactId&gt;
&lt;version&gt;5.4.9.Final&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.springframework&lt;/groupId&gt;
&lt;artifactId&gt;spring-orm&lt;/artifactId&gt;
&lt;version&gt;5.2.1.RELEASE&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.springframework&lt;/groupId&gt;
&lt;artifactId&gt;spring-tx&lt;/artifactId&gt;
&lt;version&gt;5.2.6.RELEASE&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;commons-dbcp&lt;/groupId&gt;
&lt;artifactId&gt;commons-dbcp&lt;/artifactId&gt;
&lt;version&gt;1.2.2&lt;/version&gt;
&lt;/dependency&gt;
&lt;!-- https://mvnrepository.com/artifact/com.oracle.database.jdbc/ojdbc10 --&gt;
&lt;dependency&gt;
&lt;groupId&gt;com.oracle.database.jdbc&lt;/groupId&gt;
&lt;artifactId&gt;ojdbc10&lt;/artifactId&gt;
&lt;version&gt;19.7.0.0&lt;/version&gt;
&lt;/dependency&gt;
&lt;/dependencies&gt;
&lt;build&gt;
&lt;finalName&gt;SpringMVCwithHibernate&lt;/finalName&gt;
&lt;/build&gt;
&lt;/project&gt;

答案1

得分: 1

显然,您正在尝试在Java 8上使用Oracle JDBC驱动程序ojdbc10,这是不受支持的。您可以选择以下方式之一:

  • 切换到Java 10或更高版本
  • 将JDBC驱动程序降级为ojdbc8
<dependency>
    <groupId>com.oracle.database.jdbc</groupId>
    <artifactId>ojdbc8</artifactId>
    <version>12.2.0.1</version>
</dependency>
英文:

Apparently you are trying to use Oracle JDBC driver ojdbc10 on the Java 8, which is not supported. You can either:

  • switch to Java 10 or higher
  • downgrade the JDBC driver to ojdbc8:
&lt;dependency&gt;
&lt;groupId&gt;com.oracle.database.jdbc&lt;/groupId&gt;
&lt;artifactId&gt;ojdbc8&lt;/artifactId&gt;
&lt;version&gt;12.2.0.1&lt;/version&gt;
&lt;/dependency&gt;

huangapple
  • 本文由 发表于 2020年9月1日 19:15:05
  • 转载请务必保留本文链接:https://go.coder-hub.com/63686560.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定