<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                補充知識點: 事務的傳播特性:在當前的執行環境中。如果有多個方法嵌套互相調用的話,那么事務的特性必將從第一個方法傳播到第二個、第三個。。。。 ~~~ /*事務的傳播性。如果當前執行環境中有事務,那么則會一直在 * 傳播環境中傳播下去。如果沒有事務那么則會創建一個事務 * 默認就是required * 而readOnly屬性則是規定該事務只能是一些select操作。而insert,update等 * 動作是不能執行的。因為readonly的限制,而且拿到readonly=true的transation * 的話它的執行效率是比前者高的 * 還有更多事務配置請在: *http://static.springsource.org/spring/docs/2.5.6/reference/transaction.html#transaction-strategies * 9.5.6.1. @Transactionalsettings 中查看 */ @Transactional(propagation=Propagation.REQUIRED,readOnly=true) public void save(User u){ u.setName("zhanglong"); UserLog log = new UserLog(); log.setMsg("useradded"); userDaoImpl.save(u); userLogDaoImpl.save(log); } ~~~ 下面看一個xml配置事務的案例: 1、?編寫業務邏輯操作的簡單方法: ~~~ @Component("userService") public class UserServiceImpl implements UserService{ @Resource private UserDao userDaoImpl; @Resource private UserLogDao userLogDaoImpl; public UserLogDao getUserLogDaoImpl() { return userLogDaoImpl; } public void setUserLogDaoImpl(UserLogDao userLogDaoImpl) { this.userLogDaoImpl = userLogDaoImpl; } public UserDao getUserDaoImpl() { return userDaoImpl; } public void setUserDaoImpl(UserDao userDaoImpl) { this.userDaoImpl = userDaoImpl; } public void save(User u){ u.setName("zhanglong"); UserLog log = new UserLog(); log.setMsg("user added"); userDaoImpl.save(u); userLogDaoImpl.save(log); } } ~~~ 2、? 編寫XML配置文件,將事務加上去: 下面的文件主要包括配置數據庫和指定事務前一段不用看。我們主要看事務在xml中的配置 1、? 配置事務管理器transactionManager 2、?配置事務要管理的方法tx:advice 3、?配置AOP將邏輯事務織入到相應的方法上去 ~~~ <?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" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" 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 http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd"> <context:annotation-config /> <!-- 配置容器資源掃描的包 --> <context:component-scan base-package="com.spring" /> <!-- 將前面類寫入容器 --> <bean id="logInterceptor" class="com.spring.aop.LogInterceptor" /> <!-- 配置數據源 <bean id="myDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <property name="driverClassName" value="com.mysql.jdbc.Driver"/> <property name="url" value="jdbc:mysql://localhost:3306/sms"/> <property name="username" value="root"/> <property name="password" value="root"/> </bean> --> <!-- placeholder 占位符 --> <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="locations"> <value>classpath:jdbc.properties</value> </property> </bean> <!-- 配置dataSource --> <bean id="dataSource" destroy-method="close" class="org.apache.commons.dbcp.BasicDataSource"> <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> <!-- 將配置好的dataSource注入到SessionFactory中--> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="dataSource" ref="dataSource"/> <property name="mappingResources"> <list> <value>com/spring/model/user.hbm.xml</value> <value>com/spring/model/userlog.hbm.xml</value> </list> </property> <property name="hibernateProperties"> <value> hibernate.dialect=org.hibernate.dialect.MySQLDialect hibernate.show_sql=true hibernate.hbm2ddl.auto=create </value> </property> </bean> <!-- ---------------------------以上是數據源和sessionFactory的配置 ----------------------------- --> <!-- 聲明式事務管理,事務需要數據源,從sessionFactory中拿到 這是一個AOP的應用 --> <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory" /> </bean> <!-- 配置事務要管理的方法 --> <tx:advice transaction-manager="transactionManager" id="txManager"> <tx:attributes> <tx:method name="save" read-only="true"/> </tx:attributes> </tx:advice> <!-- 配置aop設置切面和織入點邏輯 --> <aop:config> <aop:pointcut id="entryPointMethod" expression="execution(public * com.spring.service..*.*(..))"/> <aop:advisor advice-ref="txManager" pointcut-ref="entryPointMethod" /> </aop:config> </beans> ~~~ ### 文檔參考Spring官方文檔的:9.5.8.?Advisingtransactional operations [http://static.springsource.org/spring/docs/2.5.6/reference/transaction.html#transaction-declarative-applying-more-than-just-tx-advice](http://static.springsource.org/spring/docs/2.5.6/reference/transaction.html#transaction-declarative-applying-more-than-just-tx-advice)
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看