Minimize Spring Boot Time

In my opinion, SpringBoot projects take a long time to load. This is probably because SpringBoot is setting up the components for you, some of which you don't even need. The most obvious task is to remove unnecessary dependencies from your class path. However, this is not enough.

Is there a way to find out which SpringBoot modules are being configured for you, to choose what you don't need and disable them?

Is there anything else to speed up startup time for SpringBoot applications in general?

+14
java spring spring-boot
Feb 29 '16 at 20:42 on
source share
1 answer

I can say that I am launching a large (800,000+ lines of code) application using soothing web services through Spring MVC, JMS, Atomikos, Hibernate, JMX and built-in Tomcat transactions. This will launch the application on my local desktop in about 19 seconds.

Spring Boot tries not to configure modules that you are not using. However, it is easy to introduce additional dependencies and configuration that you did not plan.

Remember that Spring Boot follows the concept of configuration over configuration and simply placing the library in your class path may cause Spring Boot to try to configure the module to use the library. Also, by doing something as simple as annotating your class with @RestController, you run Spring Boot to automatically configure the entire Spring MVC stack.

You can see what is happening under the covers, and turning on debug logging is as easy as specifying --debug when starting the application from the command line. You can also specify debug = true in your application.properties.

Alternatively, you can set the logging level in application.properties as simple as:

logging.level.org.springframework.web: DEBUG logging.level.org.hibernate: ERROR

If you find a module with automatic configuration that you do not need, you can disable it. Documents for this can be found here: http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#using-boot-disabling-specific-auto-configuration

An example would look like this:

 @Configuration @EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class}) public class MyConfiguration { } 
+25
Mar 01 '16 at 3:01
source share
— -



All Articles