我们都知道springboot 由于内置tomcat(中间件)直接用启动类就可以启动了。
而且我们有时想代码给程序设置一些默认参数,所以使用方法Springboot.setDefaultProperties(map)
SpringApplication application = new SpringApplication(startClass);
//
Map params = new HashMap<>();
params.put("lai.ws.test","test");
application.setDefaultProperties(params);
ApplicationContext context = application.run(startClass,args);
于是启动后发现 lai.ws.test 居然是null,也就是参数设置不成功,百思不得其解。为此还断点进入SpringApplication 的源码里。最后发现以下源码
/**
* Static helper that can be used to run a {@link SpringApplication} from the
* specified sources using default settings and user supplied arguments.
* @param primarySources the primary sources to load
* @param args the application arguments (usually passed from a Java main method)
* @return the running {@link ApplicationConte