Spring Transaction Management not working with Spring Boot + MyBatis?
<p>I am trying to get Spring Transaction Management working in my new Spring Boot + MyBatis application.</p>

<p>So far I have managed to get everything working with minimal issues - it's just getting the <code>@Transactional</code> annotation to function correctly. Currently, all statements are committed immediately regardless of whether the method is annotated or not.</p>

<p>Spring Boot does so much of the boilerplate configuration for you that it's difficult to find the missing link.</p>

<p>My <code>build.gradle</code> contains the following dependencies:</p>

<pre><code>compile("org.springframework.boot:spring-boot-starter-amqp")
compile("org.mybatis.spring.boot:mybatis-spring-boot-starter:1.0.0")
compile("mysql:mysql-connector-java:5.1.38")
</code></pre>

<p>My <code>application.properties</code> contains the following datasource configuration:</p>

<pre><code>spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/my_db
spring.datasource.username=my_user
spring.datasource.password=my_pass
</code></pre>

<p>A simple example of a method in a bean that is not acting as expected is as follows:</p>

<pre><code>@Transactional
public void performTransactionTest() throws Exception {

    Person person = new Person();
    person.setPersonId(123);
    personMapper.insert(person);

    throw new Exception("This should force a rollback!");

}
</code></pre>

<p>The Exception gets thrown but the record has already been inserted.</p>

<p>There is basically no documentation currently in existence on transaction configuration for Spring Boot AND MyBatis together but as far as I understand, it should mostly wire itself up as would be done manually in a Spring + MyBatis application and where it doesn't - we are able to configure it further. With that said I have tried the following configurations in my <code>applicationContext.xml</code> with no luck:</p>

<pre><code>&lt;tx:annotation-driven proxy-target-class="true" transaction-manager="transactionManager" /&gt;

&lt;bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"&gt;
    &lt;property name="dataSource" ref="dataSource" /&gt;
&lt;/bean&gt;

&lt;bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"&gt;
    &lt;property name="dataSource" ref="dataSource" /&gt;
&lt;/bean&gt;
</code></pre>

<p>I can confirm that even without any of the above configurations a DataSourceTransactionManager is configured with the same DataSource that the MyBatis mappers' SqlSession uses.</p>

<p>Any help or ideas that could push me in the right direction would be greatly appreciated. If you require any further information I am happy to provide it!</p>

<p>Thanks in advance!</p>

<p>Xandel</p>