今天在写一个测试注解式事务的程序,不知道我的action一配置注解@Transactional,程序就运行不正常,请求各位帮忙看看是什么问题,部分代码如下:
1.接口:
package com.test.service;
public interface CifService {
public void save();
}
2.接口实现:
[color=red]//@Transactional(就是这个地方,我打开注释后就出错了,我想在save方法中使用事务)[/color]
public class CifServiceImpl implements CifService {
[color=red]……(省略无关代码) [/color] @Override
public void save() {
jdbcTemplate.update("update cif set introduction='11111' where cifname='test'");
// jdbcTemplate.update("update cif set introduction='2222' where cifname='aaaa");
}
}
3.JUnit测试类
public class TestCifService {
private static CifServiceImpl cifServiceImpl;
@BeforeClass
public static void setUpBeforeClass() throws Exception {
try{
ApplicationContext ctx = new ClassPathXmlApplicationContext("config/spring_config.xml");
cifServiceImpl = (CifServiceImpl) ctx.getBean("cifServiceImpl");
}catch(RuntimeException e){
e.printStackTrace();
}
}
@Test public void save(){
cifServiceImpl.save();
}
}
4.spring配置文件:
5.出错信息:
java.lang.ClassCastException: $Proxy10 cannot be cast to com.test.service.impl.CifServiceImpl
各位帮忙看一下,谢谢!