project/spring/springboot/启动.md

3.2 KiB
Raw Blame History

启动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)
SpringApplication.run(PrimarySources.class, args);
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
  6. 加载类,创建实例,排序。
  7. 找到main方法的类
public ClassLoader getClassLoader() {
    if (this.resourceLoader != null) {
        return this.resourceLoader.getClassLoader();
    }
    return ClassUtils.getDefaultClassLoader();
}
// Run the Spring application, creating and refreshing a new ApplicationContext.
.run(args)
listeners.starting()
DefaultApplicationArguments              (new SimpleCommandLineArgsParser()).parse(args)