spring的事务配置参考

<!-- 启用aspectj AOP -->

<aop:aspectj-autoproxy proxy-target-class="true"/>

 

<!-- 数据源定义  -->

<jee:jndi-lookup id="dataSource" jndi-name="java:comp/env/jdbc/JNDIDS" />

    

 <!-- 事务配置 -->

    <bean id="transactionManager"

        class="org.springframework.jdbc.datasource.DataSourceTransactionManager">

        <property name="dataSource" ref="dataSource" />

    </bean>

    

<!-- 事务拦截 -->

<tx:advice id="txAdvice" transaction-manager="transactionManager">

<tx:attributes>

<tx:method name="get*" propagation="REQUIRED" read-only="true"/>

<tx:method name="*" propagation="REQUIRED"/>

</tx:attributes>

</tx:advice>

 

<!-- 被拦截类配置,事务的粒度放在了service层 -->

<aop:config>

<aop:pointcut id="serviceOperation" expression="execution(* com.test..service.*Service.*(..))"/>

<aop:advisor advice-ref="txAdvice" pointcut-ref="serviceOperation"/>

</aop:config>

 

<!-- iBatis配置 -->

<bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">

<!-- jboss5 不支持通配符* -->

<property name="configLocations" value="classpath*:ibatis/**.ibatis.config.xml"/>

<property name="dataSource" ref="dataSource"/>

      </bean>

 

<!-- DAO定义 -->

    <bean id="commonDao" class="com.core.dao.IBatisCommonDao">

       <property name="sqlMapClient" ref="sqlMapClient"></property>

    </bean>

 

 

 

补充:

对于上述使用web应用本身的jndi数据源,需要在webapp/META-INF目录下新建context.xml文件,并且添加文件内容:

<Context>

<Resource name="jdbc/JNDIDS" auth="Container"

type="javax.sql.DataSource" driverClassName="com.jdbc.MysqlDriver"

url="jdbc:mysql://102.73.143.77/CLIENT_CHARSET=GBK,CHARSET=ASCII,database=pv_test,LOB_Support=OFF"

maxActive="5" maxldle="5" initialSize="2" maxWait="-1" username="zts"

password="zst" />

</Context>

猜你喜欢

转载自zengshaotao.iteye.com/blog/2190630
今日推荐