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.transapackage?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?{
// 自動(dòng)注入DAO(接口注入)
@Autowired
private?BookStore?bookStoreImpl;
// 添加事物注解
@Transactional
@Override
public?void?purchaseBook(String?userName,String?bookName)?{
// 查看購(gòu)買書的價(jià)格
int?price?=?bookStoreImpl.getBookByName(bookName);
// 更新庫(kù)存
bookStoreImpl.updateBookStore(bookName);
// 更新客戶的錢
bookStoreImpl.updateCustomerMoney(userName,?price);
}
}一添加@Transactional注解就拋上面的錯(cuò)誤,好多人說是動(dòng)態(tài)代理中拋出來的,但是我的Bean都是接口注入的也還是報(bào)錯(cuò),下面是事物的相關(guān)配置,哪位大神幫忙看看,多謝!<!--?配置自動(dòng)掃描包?-->
<context:component-scan?base-package="com.lzj.Spring_second.test3"></context:component-scan>
<!--?引入外部數(shù)據(jù)?-->
<context:property-placeholder?location="classpath:com/lzj/Spring_second/test3/config/data.properties"/>
<!--?通過數(shù)據(jù)源連接數(shù)據(jù)庫(kù)?-->
<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"/>
添加回答
舉報(bào)
0/150
提交
取消