Minimise Spring Boot Startup Time [duplicate]












21
















This question already has an answer here:




  • Speed up Spring Boot startup time

    7 answers




In my opinion SpringBoot projects take a long time to load. This probably happens because SpringBoot is configuring components for you, some of which you might not even need.
The most obvious thing to do is to remove unnecessary dependancies from your class path. However, that is not enough.



Is there any way to find out which modules SpringBoot is configuring for you to pick out what you don't need and disable them?



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










share|improve this question















marked as duplicate by naXa, Community Jan 2 at 9:56


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.



















  • A link that might come in handy: spring.io/blog/2018/12/12/how-fast-is-spring

    – Marged
    Jan 1 at 21:51
















21
















This question already has an answer here:




  • Speed up Spring Boot startup time

    7 answers




In my opinion SpringBoot projects take a long time to load. This probably happens because SpringBoot is configuring components for you, some of which you might not even need.
The most obvious thing to do is to remove unnecessary dependancies from your class path. However, that is not enough.



Is there any way to find out which modules SpringBoot is configuring for you to pick out what you don't need and disable them?



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










share|improve this question















marked as duplicate by naXa, Community Jan 2 at 9:56


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.



















  • A link that might come in handy: spring.io/blog/2018/12/12/how-fast-is-spring

    – Marged
    Jan 1 at 21:51














21












21








21


10







This question already has an answer here:




  • Speed up Spring Boot startup time

    7 answers




In my opinion SpringBoot projects take a long time to load. This probably happens because SpringBoot is configuring components for you, some of which you might not even need.
The most obvious thing to do is to remove unnecessary dependancies from your class path. However, that is not enough.



Is there any way to find out which modules SpringBoot is configuring for you to pick out what you don't need and disable them?



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










share|improve this question

















This question already has an answer here:




  • Speed up Spring Boot startup time

    7 answers




In my opinion SpringBoot projects take a long time to load. This probably happens because SpringBoot is configuring components for you, some of which you might not even need.
The most obvious thing to do is to remove unnecessary dependancies from your class path. However, that is not enough.



Is there any way to find out which modules SpringBoot is configuring for you to pick out what you don't need and disable them?



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





This question already has an answer here:




  • Speed up Spring Boot startup time

    7 answers








java spring spring-boot optimization startup






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 1 at 22:40









naXa

14.1k892137




14.1k892137










asked Feb 29 '16 at 20:42









Samantha CataniaSamantha Catania

2,10942851




2,10942851




marked as duplicate by naXa, Community Jan 2 at 9:56


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.









marked as duplicate by naXa, Community Jan 2 at 9:56


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.















  • A link that might come in handy: spring.io/blog/2018/12/12/how-fast-is-spring

    – Marged
    Jan 1 at 21:51



















  • A link that might come in handy: spring.io/blog/2018/12/12/how-fast-is-spring

    – Marged
    Jan 1 at 21:51

















A link that might come in handy: spring.io/blog/2018/12/12/how-fast-is-spring

– Marged
Jan 1 at 21:51





A link that might come in handy: spring.io/blog/2018/12/12/how-fast-is-spring

– Marged
Jan 1 at 21:51












2 Answers
2






active

oldest

votes


















32














I can tell you that I run a large (800,000+ lines of code) application, using restful webservices via Spring MVC, JMS, Atomikos transaction, Hibernate, JMX support, and embedded Tomcat. With all that, the application will start on my local desktop in about 19 seconds.



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



Remember that Spring Boot follows the convention over configuration paradigm and by simply placing a library in your class path can cause Spring Boot to attempt to configure a module to use the library. Also, by doing something as simple as annotating your class with @RestController will trigger Spring Boot to auto-configure the entire Spring MVC stack.



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



In addition, 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 detect an auto-configured module you don't want, it can be disabled. The docs 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:



@Configuration
@EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class})
public class MyConfiguration {
}





share|improve this answer

































    2














    A few additional tips which may be helpful.




    • Use OpenJ9 instead of Hotspot for development

    • If you use Hibernate, set hibernate.ddl-auto=none instead of update

    • Set vmargs to -Xquickstart

    • If you use OpenJ9 - set vmargs to -XX:TieredStopAtLevel=1 -noverify

    • If you use Hotspot - use IDE build instead of Gradle build

    • Use Undertow instead of Tomcat

    • Don't abuse annotation processing tools (mapstruct, immutables...) which will slow down the build process


    In addition:



    As this article recommends use @ComponentScan(lazyInit = true) for local dev environment.



    TL;DR




    What we want to achieve is to enable the bean lazy loading only in your local development environment and leave eager initialization for production. They say you can’t have your cake and eat it too, but with Spring you actually can. All thanks to profiles.



    @SpringBootApplication
    public class LazyApplication {

    public static void main(String args) {
    SpringApplication.run(LazyApplication.class, args);
    }

    @Configuration
    @Profile("local")
    @ComponentScan(lazyInit = true)
    static class LocalConfig {
    }

    }






    share|improve this answer
































      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      32














      I can tell you that I run a large (800,000+ lines of code) application, using restful webservices via Spring MVC, JMS, Atomikos transaction, Hibernate, JMX support, and embedded Tomcat. With all that, the application will start on my local desktop in about 19 seconds.



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



      Remember that Spring Boot follows the convention over configuration paradigm and by simply placing a library in your class path can cause Spring Boot to attempt to configure a module to use the library. Also, by doing something as simple as annotating your class with @RestController will trigger Spring Boot to auto-configure the entire Spring MVC stack.



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



      In addition, 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 detect an auto-configured module you don't want, it can be disabled. The docs 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:



      @Configuration
      @EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class})
      public class MyConfiguration {
      }





      share|improve this answer






























        32














        I can tell you that I run a large (800,000+ lines of code) application, using restful webservices via Spring MVC, JMS, Atomikos transaction, Hibernate, JMX support, and embedded Tomcat. With all that, the application will start on my local desktop in about 19 seconds.



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



        Remember that Spring Boot follows the convention over configuration paradigm and by simply placing a library in your class path can cause Spring Boot to attempt to configure a module to use the library. Also, by doing something as simple as annotating your class with @RestController will trigger Spring Boot to auto-configure the entire Spring MVC stack.



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



        In addition, 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 detect an auto-configured module you don't want, it can be disabled. The docs 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:



        @Configuration
        @EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class})
        public class MyConfiguration {
        }





        share|improve this answer




























          32












          32








          32







          I can tell you that I run a large (800,000+ lines of code) application, using restful webservices via Spring MVC, JMS, Atomikos transaction, Hibernate, JMX support, and embedded Tomcat. With all that, the application will start on my local desktop in about 19 seconds.



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



          Remember that Spring Boot follows the convention over configuration paradigm and by simply placing a library in your class path can cause Spring Boot to attempt to configure a module to use the library. Also, by doing something as simple as annotating your class with @RestController will trigger Spring Boot to auto-configure the entire Spring MVC stack.



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



          In addition, 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 detect an auto-configured module you don't want, it can be disabled. The docs 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:



          @Configuration
          @EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class})
          public class MyConfiguration {
          }





          share|improve this answer















          I can tell you that I run a large (800,000+ lines of code) application, using restful webservices via Spring MVC, JMS, Atomikos transaction, Hibernate, JMX support, and embedded Tomcat. With all that, the application will start on my local desktop in about 19 seconds.



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



          Remember that Spring Boot follows the convention over configuration paradigm and by simply placing a library in your class path can cause Spring Boot to attempt to configure a module to use the library. Also, by doing something as simple as annotating your class with @RestController will trigger Spring Boot to auto-configure the entire Spring MVC stack.



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



          In addition, 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 detect an auto-configured module you don't want, it can be disabled. The docs 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:



          @Configuration
          @EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class})
          public class MyConfiguration {
          }






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Jun 23 '18 at 10:13









          Martin Vseticka

          17.4k1996172




          17.4k1996172










          answered Mar 1 '16 at 3:01









          pczeuspczeus

          5,72842542




          5,72842542

























              2














              A few additional tips which may be helpful.




              • Use OpenJ9 instead of Hotspot for development

              • If you use Hibernate, set hibernate.ddl-auto=none instead of update

              • Set vmargs to -Xquickstart

              • If you use OpenJ9 - set vmargs to -XX:TieredStopAtLevel=1 -noverify

              • If you use Hotspot - use IDE build instead of Gradle build

              • Use Undertow instead of Tomcat

              • Don't abuse annotation processing tools (mapstruct, immutables...) which will slow down the build process


              In addition:



              As this article recommends use @ComponentScan(lazyInit = true) for local dev environment.



              TL;DR




              What we want to achieve is to enable the bean lazy loading only in your local development environment and leave eager initialization for production. They say you can’t have your cake and eat it too, but with Spring you actually can. All thanks to profiles.



              @SpringBootApplication
              public class LazyApplication {

              public static void main(String args) {
              SpringApplication.run(LazyApplication.class, args);
              }

              @Configuration
              @Profile("local")
              @ComponentScan(lazyInit = true)
              static class LocalConfig {
              }

              }






              share|improve this answer






























                2














                A few additional tips which may be helpful.




                • Use OpenJ9 instead of Hotspot for development

                • If you use Hibernate, set hibernate.ddl-auto=none instead of update

                • Set vmargs to -Xquickstart

                • If you use OpenJ9 - set vmargs to -XX:TieredStopAtLevel=1 -noverify

                • If you use Hotspot - use IDE build instead of Gradle build

                • Use Undertow instead of Tomcat

                • Don't abuse annotation processing tools (mapstruct, immutables...) which will slow down the build process


                In addition:



                As this article recommends use @ComponentScan(lazyInit = true) for local dev environment.



                TL;DR




                What we want to achieve is to enable the bean lazy loading only in your local development environment and leave eager initialization for production. They say you can’t have your cake and eat it too, but with Spring you actually can. All thanks to profiles.



                @SpringBootApplication
                public class LazyApplication {

                public static void main(String args) {
                SpringApplication.run(LazyApplication.class, args);
                }

                @Configuration
                @Profile("local")
                @ComponentScan(lazyInit = true)
                static class LocalConfig {
                }

                }






                share|improve this answer




























                  2












                  2








                  2







                  A few additional tips which may be helpful.




                  • Use OpenJ9 instead of Hotspot for development

                  • If you use Hibernate, set hibernate.ddl-auto=none instead of update

                  • Set vmargs to -Xquickstart

                  • If you use OpenJ9 - set vmargs to -XX:TieredStopAtLevel=1 -noverify

                  • If you use Hotspot - use IDE build instead of Gradle build

                  • Use Undertow instead of Tomcat

                  • Don't abuse annotation processing tools (mapstruct, immutables...) which will slow down the build process


                  In addition:



                  As this article recommends use @ComponentScan(lazyInit = true) for local dev environment.



                  TL;DR




                  What we want to achieve is to enable the bean lazy loading only in your local development environment and leave eager initialization for production. They say you can’t have your cake and eat it too, but with Spring you actually can. All thanks to profiles.



                  @SpringBootApplication
                  public class LazyApplication {

                  public static void main(String args) {
                  SpringApplication.run(LazyApplication.class, args);
                  }

                  @Configuration
                  @Profile("local")
                  @ComponentScan(lazyInit = true)
                  static class LocalConfig {
                  }

                  }






                  share|improve this answer















                  A few additional tips which may be helpful.




                  • Use OpenJ9 instead of Hotspot for development

                  • If you use Hibernate, set hibernate.ddl-auto=none instead of update

                  • Set vmargs to -Xquickstart

                  • If you use OpenJ9 - set vmargs to -XX:TieredStopAtLevel=1 -noverify

                  • If you use Hotspot - use IDE build instead of Gradle build

                  • Use Undertow instead of Tomcat

                  • Don't abuse annotation processing tools (mapstruct, immutables...) which will slow down the build process


                  In addition:



                  As this article recommends use @ComponentScan(lazyInit = true) for local dev environment.



                  TL;DR




                  What we want to achieve is to enable the bean lazy loading only in your local development environment and leave eager initialization for production. They say you can’t have your cake and eat it too, but with Spring you actually can. All thanks to profiles.



                  @SpringBootApplication
                  public class LazyApplication {

                  public static void main(String args) {
                  SpringApplication.run(LazyApplication.class, args);
                  }

                  @Configuration
                  @Profile("local")
                  @ComponentScan(lazyInit = true)
                  static class LocalConfig {
                  }

                  }







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Jan 1 at 21:43









                  naXa

                  14.1k892137




                  14.1k892137










                  answered Aug 16 '18 at 9:46









                  Mikhail KholodkovMikhail Kholodkov

                  4,83152849




                  4,83152849















                      Popular posts from this blog

                      Mossoró

                      Error while reading .h5 file using the rhdf5 package in R

                      Pushsharp Apns notification error: 'InvalidToken'