org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named 'org.springframework.transaction.interceptor.TransactionInterceptor#0' is expected to be of type 'org.aopalliance.aop.Advice' but was actually of type 'org.springframework.transaction.interceptor.TransactionInterceptor'
以下是事物管理的代码:
package com.lzj.Spring_second.test3; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @Service("bookStoreServiceImpl") public class BookStoreServiceImpl implements BookStoreService { // 自动注入DAO(接口注入) @Autowired private BookStore bookStoreImpl; // 添加事物注解 @Transactional @Override public void purchaseBook(String userName,String bookName) { // 查看购买书的价格 int price = bookStoreImpl.getBookByName(bookName); // 更新库存 bookStoreImpl.updateBookStore(bookName); // 更新客户的钱 bookStoreImpl.updateCustomerMoney(userName, price); } }
只要一添加@Transactional就报错,以下是事物的相关配置
<!-- 配置自动扫描包 --> <context:component-scan base-package="com.lzj.Spring_second.test3"></context:component-scan> <!-- 引入外部数据 --> <context:property-placeholder location="classpath:com/lzj/Spring_second/test3/config/data.properties"/> <!-- 通过数据源连接数据库 --> <bean id="sqlConnctionDataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"> <property name="user" value="${user}"></property> <property name="password" value="${password}"></property> <property name="driverClass" value="${driverClass}"></property> <property name="jdbcUrl" value="${jdbcUrl}"></property> </bean> <!-- 配置事物管理器 --> <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="sqlConnctionDataSource"></property> </bean> <!-- 启用事物管理器注解 --> <tx:annotation-driven transaction-manager="transactionManager"/>
有人说是动态代理中报出来的错误,说动态代理要求接口注入,但是我的是接口注入也还是出现此问题怎么办,求大神解决!多谢!
问题已经解决,原因是包的问题
请问你是怎么解决的,说详细的好吗?