Declarative transaction management

Now, let's see how we can implement Spring declarative transaction management.

Our Messages App is so simple that it works fine without transaction management. For demonstration purpose, let's add another requirement to the /messages (POST) API. Let's say we want to have a report to show the statistics of hourly posted messages. We can calculate the statistics using an SQL query. Or we can update the statistics after saving a message and save it into a table that will hold this information in the database. Let's go with the second approach so that we can use declarative transaction management.

In practice, if our Message App had traffic like Disqus (, you would probably want to take a ...

Get Building Applications with Spring 5 and Vue.js 2 now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.