Transaction in spring boot I am using spring boot in my application.

@EnableAutoConfiguration
@SpringBootApplication
public class PushMysqlTestApplication implements CommandLineRunner {
    private static Logger LOGGER = LoggerFactory.getLogger(RunQuery.class);
    @Autowired
    JdbcTemplate jdbcTemplate;


    public static void main(String[] args) throws InterruptedException {
        SpringApplication.run(PushMysqlTestApplication.class, args);
    }

    @Override
    public void run(String... args) throws Exception {
        startTransaction();
    }


    public void startTransaction() throws InterruptedException {
        LOGGER.info("=========== Transaction started ===========");
        jdbcTemplate.execute("start transaction");
        jdbcTemplate.execute("select * from push_multithread where status = 1 for update");
        Thread.sleep(5000);
        jdbcTemplate.execute("update push_multithread set status = 30 where id=1");
        Thread.sleep(10000);
        jdbcTemplate.execute("commit");
        LOGGER.info("========= Transaction ending ===========");
    }


}


What the above code does is, it starts transaction, update a table and commit using JDBCTemplate.

Is their any better way to achieve above transation in spring boot using anootations or JPA etc?
Did you try to use google for this? You have multiple way to do this :P

For example: @Transactional annotation on method.

Or using XML file to wrap methods with transaction.

Just look for this on google: https://spring.io/guides/gs/managing-transactions/