Spring @TransactionalEventListener not working as expected
<p>I am trying to listen to an event using @TransactionalEventListener but the event gets listened even before the entire transaction is over. The event is listened even if the method throws exception.</p>

<p>Here is the sample code of what i am trying to do</p>

<pre><code>@Component
public class SampleListener{

    @TransactionalEventListener
    public void handleSomeTransactionalEvent(SampleEvent event){
      //Some Logic
    }
}

@Service
@Transactional
public class SampleInsertService{

     @Autowired
     private ApplicationEventPublisher applicationEventPublisher;

     public void someTransactionalMethod(SomeDTO someDTO){
          //Delete all call

          //Again Insert all calls

          //Publish event after insert
          applicationEventPublisher.publishEvent(new SampleEvent(this, String.EventType, someDTO));

          /** Some other call to DB which throws exception **/
     }

}


public class SampleEvent implements ApplicationEvent{

     private String eventType;

     public SampleEvent(Object source, String eventType, SampleDTO sampleDTO){
           //some logic
     }

}
</code></pre>

<p>In this scenario, my listener is getting called as soon as insert is complete in my transaction method. I believe this should get called after all DB calls are over and commit is complete. Am I missing something. I am using Spring 4.3.0. Please guide me on this.</p>