title: Spring Data MongoDB @Transactional failure
body: <p>Could someone please tell me why this spring transaction is not rolling back appropriately?</p>
  
  <p><strong>The error I get is this:</strong></p>
  
  <pre><code>org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.springframework.transaction.PlatformTransactionManager' available
  </code></pre>
  
  <p><strong>This is my repository with a save transaction that will intentionally fail:</strong></p>
  
  <pre><code>@Repository
  public class TransactionalRepository {
  
      private final PlayerRepository playerRepository;
  
      @Autowired
      public TransactionalRepository(PlayerRepository playerRepository) {
          this.playerRepository = playerRepository;
      }
  
      public Player saveSuccess(Player player) {
          return playerRepository.save(player);
      }
  
      @Transactional
      public Player saveFail(Player player) {
          player.setName("FAIL"); // should not be saved in DB if transaction rollback is successful
          player = playerRepository.save(player);
          throw new IllegalStateException("intentionally fail transaction");
      }
  }
  </code></pre>
  
  <p><strong>And here is the test:</strong></p>
  
  <pre><code>@RunWith(SpringRunner.class)
  @SpringBootTest
  public class MongoTransactionApplicationTests {
  
      @Autowired
      public TransactionalRepository playerRepository;
  
      @Test
      public void contextLoads() {
  
          Player player = new Player();
          player.setId(UUID.randomUUID().toString());
          final String PLAYER_NAME = "new-"+player.getId().subSequence(0,8);
          player.setName(PLAYER_NAME);
          player = playerRepository.saveSuccess(player);
  
          try {
              player = playerRepository.saveFail(player);
          } catch (IllegalStateException e) {
              // this is supposed to fail
          }
  
          Assert.assertEquals(PLAYER_NAME, player.getName());
      }
  
  }
  </code></pre>
  
  <p><a href="https://github.com/DinkoTontchev/mongo-transaction" rel="nofollow noreferrer">Download all the code here if you want to see it run</a></p>