Showing posts with label Spring Boot. Show all posts
Showing posts with label Spring Boot. Show all posts

Saturday, 12 March 2022

Detecting a active transaction in spring application

Sometimes we need to use transactions (@Transactional) in code. We use @Transactional annotation on class and method to generate transactions.

In order to troubleshoot transaction issues, it could be helpful to verify if we have an active transaction in the current method or not.

Spring has provided a class called TransactionSychronizationManager. This class has a static method that allows us to know whether we are in a transaction (active transaction or no transaction), called isActualTransactionActive().

You can call this method and print output in logs. It will be true for active transactions false otherwise.

For example :

logger.error("Transaction is active " + TransactionSynchronizationManager.isActualTransactionActive());

Friday, 16 August 2019

Spring Boot | Disable the Spring Banner in logs

When we start spring application below banner appears in logs.


You can remove this by using below properties in application.properties.


spring.main.banner-mode=off

Clean logs after applying this change.



Thursday, 15 August 2019

Spring Boot RESTful Web Service Complete Example

While exploring spring boot, I have decided to implement simple REST service to demonstrate GET, POST, PUT, and DELETE calls.

Prerequisite for this project :

- Eclipse with STS (Spring tool Suite) plugin
- SOAPUI
- JAVA 8
- Maven

1. Create Eclipse project.
Select File->New-> Project->Spring Starter Project
Follow the wizards and finally click on finish




2. Define Employee bean.