0

I want to create a new Spring Boot web application.

My structure should be the following:

com.base.package
                MyApplication
                config
                domain
                repository
                service
                web

I can go two ways:

  1. Annotate MyApplication with @SpringBootApplication and let it find controllers, JPA repositories etc.
  2. Use @EnableWebMvc, @EnableJpaRepostories and so on along with @ComponentScan(basePackages=...) in order to point the base packeges for different component types explicitly.

I would happily go with the first approach but there is a concern that it will take more time to start the application then (if the app codebase grows significantly) because Spring would scan everything instead of particular packages. But it anyway should read all these files to find the beans at least once.

So the question is:

Is the Spring (Boot) smart enough to scan all subpackeges for the beans only once or it would add an overhead to leave it with the default configuration?

Nailgun
  • 3,999
  • 4
  • 31
  • 46
  • Have you tested it? Test and measure. The latter will probably be faster but requires more work. Packages should be scanned only once. – M. Deinum Dec 15 '15 at 09:43
  • @M. Deinum Thanks for the response. For a sample application the results are the same. I don't think I can effectively simulate a real application here. So I would like to hear an answer from someone who actually knows how it works. – Nailgun Dec 15 '15 at 10:13
  • 1
    The `@SpringBootApplication` does more only adding the `@Enable*` annotations isn't going to bootstrap an embedded container for instance, also you would need to manually know and add what to configure. Instead of prematurely optimizing just go with option 1 if it becomes to slow (for your needs) see what you can fix – M. Deinum Dec 15 '15 at 10:14

0 Answers0