title: How to use @Transactional annotation in mybatis-spring?
body: <p>I tried to use <code>@Transactional</code> annotation in <code>spring</code> and <code>mybatis</code> using <code>mybatis-spring</code> dependency. This is the service layer.</p>
  
  <pre><code>@Service
  public class OracleService {
  
      @Autowired
      private TestMapper mapper;
  
      @Autowired
      private PlatformTransactionManager transactionManager;
  
      @Transactional(propagation = Propagation.REQUIRED,
                     rollbackFor = Exception.class,
                     value = "transactionManager")
      void insert1() {
          TestModel testModel = new TestModel(1, "title1", "content1");
          mapper.insert(testModel);
          throw new RuntimeException();
      }
  }
  </code></pre>
  
  <p>As you can see, a <code>RuntimeException</code> is thrown out in <code>insert1()</code>, so the insert operation should fail. But in fact, it didn't. The record was inserted successfully. Why?</p>
  
  <p>Here is my main method.</p>
  
  <pre><code>public class Launcher {
      public static void main(String[] args) {
          ApplicationContext cxt = new ClassPathXmlApplicationContext("spring-config.xml");
          OracleService oracleService = cxt.getBean(OracleService.class);
          try {
              oracleService.insert1();
          } catch(Exception e) {
              System.out.println("Exception occurred!");
          }
      }
  }
  </code></pre>
  
  <p>Spring configuration.</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;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:tx="http://www.springframework.org/schema/tx"
  
         xsi:schemaLocation="http://www.springframework.org/schema/beans
         http://www.springframework.org/schema/beans/spring-beans.xsd
         http://www.springframework.org/schema/context
         http://www.springframework.org/schema/context/spring-context.xsd
         http://www.springframework.org/schema/tx
         http://www.springframework.org/schema/tx/spring-tx.xsd"&gt;
  
  
      &lt;context:component-scan base-package="com.database.learn"/&gt;
  
      &lt;bean id="oracleDataSource" class="oracle.jdbc.pool.OracleDataSource"&gt;
          &lt;property name="URL" value="OracleJdbcUrl"/&gt;
          &lt;property name="user" value="user"/&gt;
          &lt;property name="password" value="password"/&gt;
      &lt;/bean&gt;
  
      &lt;bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"&gt;
          &lt;property name="dataSource" ref="oracleDataSource"/&gt;
          &lt;property name="configLocation" value="classpath:mybatis-config.xml"/&gt;
      &lt;/bean&gt;
  
      &lt;bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"&gt;
          &lt;property name="dataSource" ref="oracleDataSource" /&gt;
      &lt;/bean&gt;
  
      &lt;bean id="testMapper" class="org.mybatis.spring.mapper.MapperFactoryBean"&gt;
          &lt;property name="mapperInterface" value="com.database.learn.TestMapper"/&gt;
          &lt;property name="sqlSessionFactory" ref="sqlSessionFactory"/&gt;
      &lt;/bean&gt;
      &lt;tx:annotation-driven transaction-manager="transactionManager" /&gt;
  &lt;/beans&gt;
  </code></pre>
  
  <p>I used the following dependencies in <code>pom.xml</code></p>
  
  <pre><code>    &lt;dependency&gt;
          &lt;groupId&gt;org.mybatis&lt;/groupId&gt;
          &lt;artifactId&gt;mybatis&lt;/artifactId&gt;
          &lt;version&gt;3.4.1&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.mybatis&lt;/groupId&gt;
          &lt;artifactId&gt;mybatis-spring&lt;/artifactId&gt;
          &lt;version&gt;1.3.0&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;com.oracle&lt;/groupId&gt;
          &lt;artifactId&gt;ojdbc6&lt;/artifactId&gt;
          &lt;version&gt;11.2.0.3&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework&lt;/groupId&gt;
          &lt;artifactId&gt;spring-jdbc&lt;/artifactId&gt;
          &lt;version&gt;4.3.2.RELEASE&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework&lt;/groupId&gt;
          &lt;artifactId&gt;spring-context&lt;/artifactId&gt;
          &lt;version&gt;4.3.2.RELEASE&lt;/version&gt;
      &lt;/dependency&gt;
  </code></pre>