spring MVC 事物控制问题

[size=medium]在Service层配置@Transactional不起作用[/size]

下面是配置文件
<!-- Transaction manager for a single Hibernate SessionFactory (alternative to JTA) -->




<!-- Activates scanning of @Autowired -->
context:annotation-config/

<!-- Activates scanning of @Repository -->
<context:component-scan base-package="com.yxtech.android.eamos.dao"/>

是不是还需要配置什么东西呢..求解

可以这么写,(确保service在com.yxtech.android.eamos下) ,但有可能造成你单元测试事务生效但
在web应用中事务不生效,以下是解决方案:

在主容器中(applicationContext.xml),将Controller的注解排除掉


/context:component-scan

而在springMVC配置文件中将Service注解给去掉



/context:component-scan
或者仅仅扫描controller组件:

因为spring的context是父子容器,所以会产生冲突,
Controller会先进行扫描装配,而此时的Service还没有进行事务的增强处理,
得到的将是原样的Service(没有经过事务加强处理,故而没有事务处理能力) ,
最后才是applicationContext.xml中的扫描配置进行事务处理。


你的service层是放在dao这个包下的?
context:component-scan这段元素的意思是你的注解应用的范围,如果你的dao包是dao层,那么service层的@Transactional注解是不会应用到的。

[quote]如果我把包括Service的包加进去 启动时他就会报 org.springframework.beans.factory.BeanCreationException异常 [/quote]
这就是另一个错误了,把这个错误的完整信息贴出来。

检查下这个类有没有注入到spring容器中:
StaggerProgramCustomerDaoImpl

如:
@Repository
StaggerProgramCustomerDaoImpl