Manual Bean Definitions in Spring Boot
Technology: SpringBoot is one of the most used framework for Rapid Development using Spring frameworks. It provides many features out of box like auto configuration. But because of all features startup time for the application may increase.
Some foe the features provided by Spring boot out of the box features we may not need for some applications, these configurations we can disable for better performance in term of memory and also execution time.
Spring Framework provides @Conditional annotation to load provide bean for various conditional specific beans like if the profile is dev load some beans, if profile is prod load other beans.
Spring Boot is implemented this conditional way in a broader way to configure the beans based on classpath scanning.
We will create a sample web application with single endpoint hello.
And if we try to start using debug mode by adding property debug=true in application.properties file, then we can observe the below lines in console.
CONDITIONS EVALUATION REPORT
All these configuration is came from our classpath scan of the application, insteadofclasspath-scan if we can provide the autoconfiguration classes, spring boot won`t perform theclasspath-scan and startup can be reduced.
And some of the features like JMX, if we are not using in our application then we easily disable using spring.jmx.enabled=false, which can increase the performance of the application and also decrease startup time.
Suppose if we specify only configurations needed for the application like
Then startup will be decreased, the drawback of this order of the specifying beans is so important. We can overcome by creating new custom annotation and specifying the configuration files in factories file.
The advantages of doing this are that the application code no longer has to manually enumerate the configurations, and also that the ordering is now taken care of by Spring Boot. The disadvantage is that it is only useful for applications which need precisely these features, and has to be replaced or augmented in any application that wants to do something a bit different. It is still fast though - Spring Boot does a little bit of extra work for the book keeping, but not really very much.
we can use springboot as a convenient collection of pre-test and prepared configurations, by default all majority of the features are enabled, but we can control all features using annotations.The smaller number of features you use, the fewer classes are loaded, which lead to faster startup. And also we learned how to improve the application performance using custom annotation. Contact Aegis Infoways for Java Development Outsourcing Services.