- <?xml version="1.0" encoding="UTF-8"?>
- <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd">
- <!--
- - Application context definition for PetClinic on JDBC.
- -->
- <beans>
- <!-- ========================= RESOURCE DEFINITIONS ========================= -->
- <!-- Configurer that replaces ${...} placeholders with values from a properties file -->
- <!-- (in this case, JDBC-related settings for the dataSource definition below) -->
- <!--
- <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
- <property name="location" value="/WEB-INF/jdbc.properties"/>
- </bean>
- -->
- <!--
- Simple local DataSource that works in any environment.
- This uses the JDBC DriverManager to obtain connections, and does NOT perform connection
- pooling. Connection pooling is essential to all real-world applications.
- This definition is good for getting started, as it introduces no dependencies beyond
- the JDK, but DriverManagerDataSource is not intended for production usage.
- -->
- <!--
- <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
- <property name="driverClassName" value="${jdbc.driverClassName}"/>
- <property name="url" value="${jdbc.url}"/>
- <property name="username" value="${jdbc.username}"/>
- <property name="password" value="${jdbc.password}"/>
- </bean>
- -->
- <!-- 在spring中直接配置jdbc链接
- <bean id="dataSource"
- class="org.springframework.jdbc.datasource.DriverManagerDataSource">
- <property name="driverClassName"
- value="net.sourceforge.jtds.jdbc.Driver" />
- <property name="url"
- value="jdbc:jtds:sqlserver://localhost:1433/wmjqxgl;SelectMethod=cursor;charset=GBK;tds=8.0;lastupdatecount=true" />
- <property name="username" value="sa" />
- <property name="password" value="sa" />
- </bean>-->
- <!-- 通过proxool来配置数据源-->
- <bean id="dataSource"
- class="org.springframework.jdbc.datasource.DriverManagerDataSource">
- <property name="driverClassName"
- value="org.logicalcobwebs.proxool.ProxoolDriver" />
- <property name="url"
- value="proxool.qxgldb" />
- </bean>
- <!--
- Alternative local DataSource that works in any environment, and offers much better performance.
- Uses Apache Commons DBCP for connection pooling. See Commons DBCP documentation
- for the required JAR files. See the PetStore sample application also shipped with
- Spring, for an example of Commons DBCP usage and the necessary build script.
- Alternatively you can use another connection pool such as C3P0, similarly configured
- using Spring.
- A standalone connection pool such as Commons DBCP is a good choice for use outside an
- application server environment, including web applications running in a web container without
- JTA, or integration testing using the org.springframework.test package.
- -->
- <!--
- <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
- <property name="driverClassName" value="${jdbc.driverClassName}"/>
- <property name="url" value="${jdbc.url}"/>
- <property name="username" value="${jdbc.username}"/>
- <property name="password" value="${jdbc.password}"/>
- </bean>
- -->
- <!-- JNDI DataSource for J2EE environments -->
- <!--
- <bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
- <property name="jndiName" value="java:comp/env/jdbc/petclinic"/>
- </bean>
- -->
- <!-- Transaction manager for a single JDBC DataSource (alternative to JTA) -->
- <bean id="transactionManager"
- class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
- <property name="dataSource" ref="dataSource" />
- </bean>
- <!-- Transaction manager that delegates to JTA (for a transactional JNDI DataSource) -->
- <!--
- <bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager"/>
- -->
- <bean id="baseTransactionProxy" abstract="true"
- class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
- <property name="transactionManager">
- <ref bean="transactionManager" />
- </property>
- <property name="transactionAttributes">
- <props>
- <prop key="create*">
- PROPAGATION_REQUIRED,-Exception
- </prop>
- <prop key="update*">
- PROPAGATION_REQUIRED,-Exception
- </prop>
- <prop key="delete*">
- PROPAGATION_REQUIRED,-Exception
- </prop>
- <prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
- <prop key="retrieve*">
- PROPAGATION_REQUIRED,readOnly
- </prop>
- <prop key="*">PROPAGATION_REQUIRED,-Exception</prop>
- </props>
- </property>
- </bean>
- <!--
- 通过BeanNameAutoProxyCreator来实现spring的事务控制-->
- <bean
- class="org.springframework.transaction.interceptor.TransactionAttributeSourceAdvisor">
- <property name="transactionInterceptor"
- ref="transactionInterceptor" />
- </bean>
- <bean id="transactionInterceptor"
- class="org.springframework.transaction.interceptor.TransactionInterceptor">
- <property name="transactionManager">
- <ref bean="transactionManager" />
- </property>
- <property name="transactionAttributes">
- <props>
- <prop key="create*">
- PROPAGATION_REQUIRED,-Exception
- </prop>
- <prop key="update*">
- PROPAGATION_REQUIRED,-Exception
- </prop>
- <prop key="delete*">
- PROPAGATION_REQUIRED,-Exception
- </prop>
- <prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
- <prop key="retrieve*">
- PROPAGATION_REQUIRED,readOnly
- </prop>
- <prop key="*">PROPAGATION_REQUIRED,-Exception</prop>
- </props>
- </property>
- </bean>
- <bean
- class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
- <property name="beanNames">
- <value>*ServiceDao</value>
- </property>
- <property name="interceptorNames">
- <list>
- <value>transactionInterceptor</value>
- </list>
- </property>
- </bean>
- <!-- ========================= BUSINESS OBJECT DEFINITIONS ========================= -->
- </beans>
spring 事务配置 的一种方法
最新推荐文章于 2024-07-20 20:04:43 发布