InterviewSolution
Saved Bookmarks
| 1. |
How does the main method look like in Spring boot or code snippet of main method? |
|
Answer» Below code structure REPRESENT the main method of spring boot which use to kick start the spring boot application along with the configuration details which is in annotated form. import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; /* Below code is sample code to run the spring boot application from main method. * We have to add the ComponentScan annotation to instantiate the bean for onfigure CLASS. * Need to add the EnableAuutoConfiguration to do auto configuraion according to the * *dependencies. * SpringBootApplication annotation responsible to make the class as a spring boot application. */ @ComponentScan @EnableAutoConfiguration @SpringBootApplication public class SpringBootApplication { public static void main(String[] ARGS) { // Below syntax use to run the spring boot application with internal CONFIGURE web server, //which publish deploy and publish the web services, once this PROCESS succcessful and web //seriver is up, the web service is available for the configure request. SpringApplication.run(SpringBootApplication.class, args); } }To run the above code, we have to run the below command either from command prompt or shell: mvn spring-boot: run |
|