project/spring/springboot/启动.md

90 lines
3.2 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

## 启动shell脚本
```shell
Bean 'org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration' of type [org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration$$EnhancerBySpringCGLIB$$69797ab5] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
```
```java
SpringApplication.run(PrimarySources.class, args);
```
```java
new SpringApplication(primarySources)
setInitializers ApplicationContextInitializer.class
setListeners ApplicationListener.class
Class.forName(stackTraceElement.getClassName())
getSpringFactoriesInstances从META-INF/spring.factories获取实例通过反射创建
private static Map<String, List<String>> loadSpringFactories(@Nullable ClassLoader classLoader) {
MultiValueMap<String, String> result = (MultiValueMap)cache.get(classLoader);
if (result != null) {
return result;
} else {
try {
Enumeration<URL> urls = classLoader != null ? classLoader.getResources("META-INF/spring.factories") : ClassLoader.getSystemResources("META-INF/spring.factories");
LinkedMultiValueMap result = new LinkedMultiValueMap();
while(urls.hasMoreElements()) {
URL url = (URL)urls.nextElement();
UrlResource resource = new UrlResource(url);
Properties properties = PropertiesLoaderUtils.loadProperties(resource);
Iterator var6 = properties.entrySet().iterator();
while(var6.hasNext()) {
Entry<?, ?> entry = (Entry)var6.next();
String factoryClassName = ((String)entry.getKey()).trim();
String[] var9 = StringUtils.commaDelimitedListToStringArray((String)entry.getValue());
int var10 = var9.length;
for(int var11 = 0; var11 < var10; ++var11) {
String factoryName = var9[var11];
result.add(factoryClassName, factoryName.trim());
}
}
}
cache.put(classLoader, result);
return result;
} catch (IOException var13) {
throw new IllegalArgumentException("Unable to load factories from location [META-INF/spring.factories]", var13);
}
}
}
```
1. 设置资源加载(包含类加载器)
2. 设置资源primarySources Map
3. 设置web类型
4. 设置工厂实例ApplicationContextInitializerMETA-INF/spring.factories
5. 设置监听ApplicationListener
5. 加载类,创建实例,排序。
6. 找到main方法的类
```java
public ClassLoader getClassLoader() {
if (this.resourceLoader != null) {
return this.resourceLoader.getClassLoader();
}
return ClassUtils.getDefaultClassLoader();
}
```
```java
// Run the Spring application, creating and refreshing a new ApplicationContext.
.run(args)
```
```java
listeners.starting()
```
```java
DefaultApplicationArguments (new SimpleCommandLineArgsParser()).parse(args)
```
准备环境
设置转换器