Koskamo

Structuring code and the main application class

Document v1 · published by Koskamo editorial · updated 2026-10-04

Original source

Spring Boot imposes no specific code layout requirements, but adhering to best practices aids development. Avoid the default package, as it causes issues with @ComponentScan, @ConfigurationPropertiesScan, @EntityScan, and @SpringBootApplication by reading every class from every jar. Instead, follow Java’s recommended naming conventions using a reversed domain name, such as com.example.project. Place the main application class in a root package above other classes to define a base search package for items like JPA @Entity classes. This structure ensures component scan applies only to the project. While @SpringBootApplication is typically used on the main class, @EnableAutoConfiguration and @ComponentScan can be used instead. For domain-based structures, consider Spring Modulith. The recommended layout groups classes under the root package, with the main class containing the main method and @SpringBootApplication annotation. Scope: Spring Boot. Reviewed October 4, 2026.

Source and provenance

Original source
docs.spring.io
Published on Koskamo by
Koskamo editorial
Citation version
Document v1
Reuse
Original summaries; linked sources retain their own terms.

The original source supplies the underlying information. Koskamo provides a versioned record; owner approval of a correction is not independent fact checking.