spring+hibernate 声明式事务管理
之前在使用 spring+hibernate 声明式事务管理时,总是出错,无法进行事务管理,摸索了很久,终于明白。
既然使用 srping管理事务,那么所有的 bean都要在 springIoC中进行管理,否则何谈 spring声明式事务,包括 Dao层,service层和 controller层
在 controller层中
ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");FooService defaultFooService = (FooService) ctx.getBean("fooService");DefaultFooService defaultFooService = DefaultFooService.getInstance();