JPA环境测试成功了,加上spring就报错,查了好长时间都没找到错,各位高手帮小弟看看!
1.报错信息:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [beans.xml]: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.transaction.config.internalTransactionAdvisor': Cannot create inner bean '(inner bean)' of type [org.springframework.transaction.interceptor.TransactionInterceptor] while setting bean property 'transactionInterceptor'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)': Cannot resolve reference to bean 'transactionManager' while setting bean property 'transactionManager'; nested exception is org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [org.springframework.orm.jpa.JpaTransationManager] for bean with name 'transactionManager' defined in class path resource [beans.xml]; nested exception is java.lang.ClassNotFoundException: org.springframework.orm.jpa.JpaTransationManager
Related cause: org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [org.springframework.orm.jpa.JpaTransationManager] for bean with name 'transactionManager' defined in class path resource [beans.xml]; nested exception is java.lang.ClassNotFoundException: org.springframework.orm.jpa.JpaTransationManager
Related cause: org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [org.springframework.orm.jpa.JpaTransationManager] for bean with name 'transactionManager' defined in class path resource [beans.xml]; nested exception is java.lang.ClassNotFoundException: org.springframework.orm.jpa.JpaTransationManager
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:478)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
at java.security.AccessController.doPrivileged(Native Method)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.transaction.config.internalTransactionAdvisor': Cannot create inner bean '(inner bean)' of type [org.springframework.transaction.interceptor.TransactionInterceptor] while setting bean property 'transactionInterceptor'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)': Cannot resolve reference to bean 'transactionManager' while setting bean property 'transactionManager'; nested exception is org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [org.springframework.orm.jpa.JpaTransationManager] for bean with name 'transactionManager' defined in class path resource [beans.xml]; nested exception is java.lang.ClassNotFoundException: org.springframework.orm.jpa.JpaTransationManager
Related cause: org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [org.springframework.orm.jpa.JpaTransationManager] for bean with name 'transactionManager' defined in class path resource [beans.xml]; nested exception is java.lang.ClassNotFoundException: org.springframework.orm.jpa.JpaTransationManager2.beans.xml:<context:component-scan base-package="com.itcast"/>
<context:property-placeholder location="classpath:jdbc.properties"/>
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="${driverClassName}"/>
<property name="url" value="${url}"/>
<property name="username" value="${username}"/>
<property name="password" value="${password}"/>
<property name="initialSize" value="${initialSize}"/>
<property name="maxIdle" value="${maxIdle}"/>
<property name="minIdle" value="${minIdle}"/>
</bean>
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="persistenceXmlLocation" value="classpath:META-INF/persistence.xml" />
<property name="loadTimeWeaver">
<bean class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver"/>
</property>
</bean>
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransationManager">
<property name="entityManagerFactory" ref="entityManagerFactory"/>
</bean>
<tx:annotation-driven transaction-manager="transactionManager"/>
</beans>3.persistence.xml:<?xml version="1.0"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd" version="1.0">
<persistence-unit name="itcast" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5Dialect"/>
<property name="hibernate.max_fetch_depth" value="3"/>
<property name="hibernate.hbm2ddl.auto" value="update"/>
<property name="hibernate.jdbc.fetch_size" value="18"/>
<property name="hibernate.jdbc.batch_size" value="10"/>
<property name="hibernate.show_sql" value="false"/>
<property name="hibernate.format_sql" value="false"/>
</properties>
</persistence-unit>
</persistence>
1.报错信息:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [beans.xml]: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.transaction.config.internalTransactionAdvisor': Cannot create inner bean '(inner bean)' of type [org.springframework.transaction.interceptor.TransactionInterceptor] while setting bean property 'transactionInterceptor'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)': Cannot resolve reference to bean 'transactionManager' while setting bean property 'transactionManager'; nested exception is org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [org.springframework.orm.jpa.JpaTransationManager] for bean with name 'transactionManager' defined in class path resource [beans.xml]; nested exception is java.lang.ClassNotFoundException: org.springframework.orm.jpa.JpaTransationManager
Related cause: org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [org.springframework.orm.jpa.JpaTransationManager] for bean with name 'transactionManager' defined in class path resource [beans.xml]; nested exception is java.lang.ClassNotFoundException: org.springframework.orm.jpa.JpaTransationManager
Related cause: org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [org.springframework.orm.jpa.JpaTransationManager] for bean with name 'transactionManager' defined in class path resource [beans.xml]; nested exception is java.lang.ClassNotFoundException: org.springframework.orm.jpa.JpaTransationManager
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:478)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
at java.security.AccessController.doPrivileged(Native Method)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.transaction.config.internalTransactionAdvisor': Cannot create inner bean '(inner bean)' of type [org.springframework.transaction.interceptor.TransactionInterceptor] while setting bean property 'transactionInterceptor'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)': Cannot resolve reference to bean 'transactionManager' while setting bean property 'transactionManager'; nested exception is org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [org.springframework.orm.jpa.JpaTransationManager] for bean with name 'transactionManager' defined in class path resource [beans.xml]; nested exception is java.lang.ClassNotFoundException: org.springframework.orm.jpa.JpaTransationManager
Related cause: org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [org.springframework.orm.jpa.JpaTransationManager] for bean with name 'transactionManager' defined in class path resource [beans.xml]; nested exception is java.lang.ClassNotFoundException: org.springframework.orm.jpa.JpaTransationManager2.beans.xml:<context:component-scan base-package="com.itcast"/>
<context:property-placeholder location="classpath:jdbc.properties"/>
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="${driverClassName}"/>
<property name="url" value="${url}"/>
<property name="username" value="${username}"/>
<property name="password" value="${password}"/>
<property name="initialSize" value="${initialSize}"/>
<property name="maxIdle" value="${maxIdle}"/>
<property name="minIdle" value="${minIdle}"/>
</bean>
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="persistenceXmlLocation" value="classpath:META-INF/persistence.xml" />
<property name="loadTimeWeaver">
<bean class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver"/>
</property>
</bean>
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransationManager">
<property name="entityManagerFactory" ref="entityManagerFactory"/>
</bean>
<tx:annotation-driven transaction-manager="transactionManager"/>
</beans>3.persistence.xml:<?xml version="1.0"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd" version="1.0">
<persistence-unit name="itcast" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5Dialect"/>
<property name="hibernate.max_fetch_depth" value="3"/>
<property name="hibernate.hbm2ddl.auto" value="update"/>
<property name="hibernate.jdbc.fetch_size" value="18"/>
<property name="hibernate.jdbc.batch_size" value="10"/>
<property name="hibernate.show_sql" value="false"/>
<property name="hibernate.format_sql" value="false"/>
</properties>
</persistence-unit>
</persistence>
解决方案 »
- 如何用Coroutine 实现 经典 producer/consumer 问题?
- 在DAO中使用spring中的HibernateTemplate,如何返回受影响的行数
- HQL语句的问题!
- 使用openCms 锁定后无法解锁
- 急~~~~求助:Hibernate3.0与oracle8.1.7怎么配proxool连接池?
- struts1.2框架上如何整合struts2框架
- 高手进进,看网上资料,有些地方不太明白,请教
- 一个小问题,在线等等
- 学习java半年多了,打算研究一个开源的java项目,各位觉得jive适合吗?
- JSP 编译问题 2 为您散分 大家帮忙看看,小女谢过了!在线等!!!!!!!!!!!!!!!!!!!!!!!!!
- 一个aop中对action进行代理出现的类转换异常,详细请进
- 关于服务器调优监测工具
这个JAR包你打了没?你WEB.XML里SPRING的监听器里有初始化 BEANS.XML吗?
包含这类的jar包没有导入。还有看看版本有问题没
2.lib\aspectj目录下:(aspectjrt.jar aspectjweaver.jar)
3.lib\cglib目录下:(cglib-nodep-2.1_3.jar(动态生成字节码))
4.lib\j2ee目录下:(common-annotations.jar(依赖注入))
5.lib\jakarta-commons目录下:(commons-logging.jar (日志包),commons-pool.jar commons-dbcp.jar (使用到数据源apache开源的dbcp))以上是我导入spring2.5.4的包,另外,hibernate3.2的包全部导入了。
web.xml: <context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:beans.xml</param-value>
</context-param>
<!-- 对Spring容器进行实例化 -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
web.xml的SPRING配置没问题。问题在这!dataSource 中的 org.apache.commons.dbcp.BasicDataSource
既然你是看传智播客的DEMO那就改成
com.mchange.v2.c3p0.ComboPooledDataSource
把 c3p0-0.9.1.2.jar 加到 lib里去。
beans.xml:
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
destroy-method="close">
<property name="driverClass" value="com.mysql.jdbc.Driver" />
<property name="jdbcUrl" value="jdbc:mysql://localhost:3306/itcast" />
<property name="user" value="root" />
<property name="password" value="900503" />
<!-- 指定连接数据库连接池的最小连接数 -->
</bean>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">这个是beans.xml 头 你看看少了什么
<context:property-placeholder location="classpath:jdbc.properties"/>你要改成如下<bean id="properties"
class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<property name="locations">
<list>
<value>classpath:jdbc.properties</value>
</list>
</property>
</bean>
applicationContext.xml的schema你应该参照12楼
现在除了数据库的driverClassName=com.mysql.jdbc.Driver不一样,mysql的jar包版本不一样外,其他都是一样的,视频里面可以正常运行,怎么我就老报错呢?真郁闷。
我也有 很遗憾 报的这个 错 org.springframework.orm.jpa.JpaTransationManager
这个 JAR 中的 JpaTransationManager.class 我找不到 。
我没报错 是不是你的TOMCAT问题 我用6.0的 你呢
不用JPA了,用hibernate。