正在做的项目中,用的是spring2,项目中有一个配置文件,作了事物控制配置
<!-- metabase事务 -->
<bean id="transactionManagerRootProxy"
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"
abstract="true">
<property name="transactionManager">
<ref bean="metaTransactionManager"/>
</property>
<property name="proxyTargetClass">
<value>false</value>
</property>
<property name="transactionAttributes">
<props>
<prop key="insert*">PROPAGATION_REQUIRED,-Exception</prop>
<prop ke三y="update*">PROPAGATION_REQUIRED,-Exception</prop>
<prop key="select*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="remove*">PROPAGATION_REQUIRED,readOnly</prop>

</props>
</property>
</bean>
以前在写service时,是通过配置文件加parent进行事物控制,如
 <bean id="templateService"  parent="transactionManagerRootProxy" >   
现在我想对service使用spring注释的方式
@Service
public class RptUserColumnServiceImpl implements RptUserColumnService
{如何给这个Service类加上parent呢?请高人指点

解决方案 »

  1.   


    <?xml version="1.0" encoding="UTF-8" ?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans   http://www.springframework.org/schema/beans/spring-beans-2.5.xsd   http://www.springframework.org/schema/context   http://www.springframework.org/schema/context/spring-context-2.5.xsd"  
     
       
     <context:component-scan base-package=”com.eric.spring”>   
     </beans>    其中base-package为需要扫描的包(含所有子包) @Service用于标注业务层组件
    @Service服务层组件,用于标注业务层组件,表示定义一个bean,自动根据bean的类名实例化一个首写字母为小写的bean,例如Chinese实例化为chinese,如果需要自己改名字则:@Service("你自己改的bean名")。
      

  2.   

    <?xml version="1.0" encoding="UTF-8" ?> 
    <beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" 
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans-2.5.xsd   
    http://www.springframework.org/schema/context   
    http://www.springframework.org/schema/context/spring-context-2.5.xsd">
    <context:annotation-config />
    <!--注解式事务配置驱动-->
    <tx:annotation-driven transaction-manager="transactionManager"
    proxy-target-class="true" />
    <!--
    业务类bean的实现类标注了@Transactional注解,所以会被 tx:annotation-driven注解驱动自动织入事务增强
    --> <!-- 配置事务管理器 -->
    <bean id="transactionManager"
    class="org.springframework.orm.hibernate3.HibernateTransactionManager">
    <property name="sessionFactory">
    <ref bean="sessionFactory" />
    </property>
    </bean> <!-- 使Spring关注Annotation -->
    <context:annotation-config />
    <context:component-scan base-package="com.xx.service" />
    <context:component-scan base-package="com.xx.service" />