How do you configure the startup class in Spring Boot?
In Spring Boot, setting up the main class is very easy – just add the @SpringBootApplication annotation to the main class.
The sample code is provided below:
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
In the above code, the @SpringBootApplication annotation is a combination annotation that combines the functionalities of @EnableAutoConfiguration, @ComponentScan, and @Configuration annotations. It automatically configures, scans components, and marks the main class as a configuration class.
The SpringApplication.run(DemoApplication.class, args) method is used to start the application. It takes two parameters – the first parameter is the Class object of the startup class, and the second parameter is the runtime arguments, usually args.