springboot-SpringApplication与SpringApplicationBuilder
@SpringBootApplication public class SpringbootdemoApplication { public static void main(String[] args) { SpringApplication application = new SpringApplication(SpringbootdemoApplication.class); Map<String,Object> properties = new HashMap<>(); properties.put("server.port",0); application.setDefaultProperties(properties); application.run(args);
// new SpringApplicationBuilder(SpringbootdemoApplication.class)
// .properties("server.port=0") //随机向OS要可用端口
// .run(args);
}
public static void main(String[] args) { SpringApplication application = new SpringApplication(SpringbootdemoApplication.class); Map<String,Object> properties = new HashMap<>(); properties.put("server.port",0); application.setDefaultProperties(properties); application.setWebApplicationType(WebApplicationType.NONE); ConfigurableApplicationContext context = application.run(args); //class org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext //class org.springframework.context.annotation.AnnotationConfigApplicationContext(非web环境是这个) System.out.println(context.getClass());