我在Apache tomcat8 java-8 web应用程序上运行了一个示例 Spring 3.2 + Hibernate + Postgres 9.4。我收到了以下错误:
org.springframework.beans.factory.BeanCreationException:错误 创建名称为' employeeDao':注入自动装配的bean 依赖失败;嵌套异常是 org.springframework.beans.factory.BeanCreationException :无法 autowire字段:private org.hibernate.SessionFactory com.forum.dao.EmployeeDaoImpl.sessionFactory;嵌套异常是 org.springframework.beans.factory.BeanCreationException:错误 创建名为' sessionFactory'的bean在ServletContext中定义 资源[/WEB-INF/spring-servlet.xml]: 无法解析引用 bean' dataSource'设置bean属性' dataSource&#39 ;;嵌套 异常是org.springframework.beans.factory.BeanCreationException: 创建名称为' dataSource'的bean时出错在ServletContext中定义 resource [/WEB-INF/spring-servlet.xml]:设置属性值时出错; 嵌套异常是: org.springframework.beans.PropertyBatchUpdateException;嵌套 PropertyAccessExceptions(1)是:PropertyAccessException 1: org.springframework.beans.MethodInvocationException:Property ' driverClassName'抛出异常;嵌套异常是 java.lang.UnsupportedClassVersionError:org / postgresql / Driver 不支持的major.minor版本52.0 (无法加载类 org.postgresql.Driver)
src / resources中的database.properties文件
database.driver=org.postgresql.Driver
database.url=jdbc:postgresql://localhost:5432/sample
database.user=postgres
database.password=sujata
hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
hibernate.show_sql=true
hibernate.hbm2ddl.auto=update
弹簧servlet.xml中
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context- 3.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
<context:property-placeholder location="classpath:resources/database.properties" />
<context:component-scan base-package="com.forum" />
<mvc:annotation-driven/>
<tx:annotation-driven transaction- manager="hibernateTransactionManager"/>
<bean id="jspViewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass"
value="org.springframework.web.servlet.view.JstlView" />
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" />
</bean>
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="${database.driver}" />
<property name="url" value="${database.url}" />
<property name="username" value="${database.user}" />
<property name="password" value="${database.password}" />
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="annotatedClasses">
<list>
<value>com.forum.model.Employee</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${hibernate.dialect} </prop>
<prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
<prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop>
</props>
</property>
</bean>
<bean id="hibernateTransactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
我已经尝试了所有可用的答案 - 检查了我的JRE,JDK合规级别,postgres版本和相关的驱动程序,方言名称,正确的驱动程序。但问题仍然存在。该程序也完美适用于Mysql。我已将postgresql-9.4-1206-jdbc42.jar放在Web Content / WEB-INF / lib /文件夹中,而不是通过Add External Jars将它包含在构建路径中。以下定义有什么问题?