读书人

spring datasource 配备及事务管理

发布时间: 2012-10-26 10:30:58 作者: rapoo

spring datasource 配置及事务管理

首先配置 datasource

?我的数据源配置 来自于tomcat下 conf/context.xml

?? 在这里你可以配置数据源信息 :

context.xml 配置

?

<Resource name="jdbc/testDB" auth="Container" type="javax.sql.DataSource"   maxActive="100" maxIdle="30" maxWait="10000"   username="root" password="" driverClassName="com.mysql.jdbc.Driver"   url="jdbc:mysql://192.168.1.246:3306/TestDB?useUnicode=true&characterEncoding=utf-8"/>

?

dbonfig.properties文件 配置

jndiName=testDB

?

?

下面是applicationContextAction.xml配置文件

?

<bean id="propertyConfigurer"name="code"><bean id="transactionManager"ref="dataSource" /></bean><!-- 将所有具有@Transactional注解的Bean自动配置为声明式事务支持 --><tx:annotation-driven transaction-manager="transactionManager" />

?

具体的DAO 及Service的配置? :设置注入

?

  <bean id="sampleDAO" />   <bean id="sampleDAOProxy"      ref="sampleDAO" />      <property name="transactionManager" ref="transactionManager" />      <property name="transactionAttributes">         <props>            <prop key="*">PROPAGATION_REQUIRED,-Exception</prop>         </props>      </property>   </bean>   <bean id="sampleService"      ref="sampleDAOProxy" />   </bean>

?

?struts2 Action的配置:构造器注入

?

<bean id="SampletAction" /></bean>

?其他配置 可以参考下面超链

?

http://topinking.iteye.com/blog/248839

?

其实spring的 声明式事务管理配置,有5种方式 :下面是更为清晰的

?

根据代理机制的不同,总结了五种Spring事务的配置方式,配置文件如下

?

http://jiake.iteye.com/blog/599418

?

?

读书人网 >软件架构设计

热点推荐