Spring / Spring Boot 4 Basics Interview Questions
What is @SpringBootApplication and what does it combine?
@SpringBootApplication is a composed annotation that is the standard entry point for Spring Boot applications. It combines three key annotations that together enable auto-configuration, component scanning, and configuration capabilities.
// @SpringBootApplication = @SpringBootConfiguration // + @EnableAutoConfiguration // + @ComponentScan @SpringBootApplication // the one annotation to rule them all public class OrderServiceApplication { public static void main(String[] args) { SpringApplication.run(OrderServiceApplication.class, args); } } // What each constituent annotation does: // @SpringBootConfiguration: marks this as a Spring configuration class // (specialisation of @Configuration) // @EnableAutoConfiguration: tells Spring Boot to scan the classpath // and auto-configure beans based on what is found // e.g., finds spring-boot-starter-data-jpa -> auto-configures DataSource // @ComponentScan: scans the current package and sub-packages // for @Component, @Service, @Repository, @Controller, etc. // Default: scans the package of the annotated class // Customisations: @SpringBootApplication( // exclude specific auto-configurations: exclude = {DataSourceAutoConfiguration.class}, // scan additional packages: scanBasePackages = {"com.example.orders", "com.example.shared"} ) public class App { ... } // SpringApplication customisation in Boot 4: @SpringBootApplication public class App { public static void main(String[] args) { var app = new SpringApplication(App.class); app.setBannerMode(Banner.Mode.OFF); // disable ASCII art banner app.setLazyInitialization(true); // lazy init for faster startup app.run(args); } }
Invest now in Acorns!!! 🚀
Join Acorns and get your $5 bonus!
Acorns is a micro-investing app that automatically invests your "spare change" from daily purchases into diversified, expert-built portfolios of ETFs. It is designed for beginners, allowing you to start investing with as little as $5. The service automates saving and investing. Disclosure: I may receive a referral bonus.
Invest now!!! Get Free equity stock (US, UK only)!
Use Robinhood app to invest in stocks. It is safe and secure. Use the Referral link to claim your free stock when you sign up!.
The Robinhood app makes it easy to trade stocks, crypto and more.
Webull! Receive free stock by signing up using the link: Webull signup.
More Related questions...
