Best practices while using Spring Boot

There is no doubt that Spring Boot is the most commonly used framework when it comes to develop micro services using Java. Main reason for the popularity of Spring Boot is its very quick way of bootstrapping (thanks to its “convention over configuration” philosophy) and its very well supported community. In this blog, I am not going to the basics of Spring Boot but discuss some of the best practices that I have learnt over time:

        @Component
        class Student(name: String, age : Int, address : String?, class : Int)
        @Component
        class Teacher(name: String, age : Int, level : String?, salary : Float)
        // First enable async execution using a dedicated async threadpool 
        @Configuration
        @EnableAsync
        class AsyncConfig {
            @Bean(name = arrayOf("asyncExecutor"))
            fun asyncExecutor(): Executor? {
                val executor = ThreadPoolTaskExecutor()
                executor.corePoolSize = 50
                executor.maxPoolSize = 100
                executor.initialize()
                return executor
            }
        }

        // Annotate the long running function with async annotation as below which will ensure that it returns async and uses threads only from the above pool
            @Async("asyncExecutor")
            fun X() {
            }
        @RestController
        @RequestMapping("/api/1")
        @Timed(percentiles = {0.1, 0.5, 0.95, 0.99})
        public class TasksController {
        }
@Timed annotation above produces latency percentiles of the incoming requests and these are very useful out-of-box information to start with.