-
- <dependencies>
- <dependency>
- <groupId>org.springframework.bootgroupId>
- <artifactId>spring-boot-starter-webartifactId>
- dependency>
- <dependency>
- <groupId>org.springframework.bootgroupId>
- <artifactId>spring-boot-testartifactId>
- <version>2.7.3version>
- <scope>testscope>
- dependency>
- dependencies>
-
图一的流程来解析pom.xml文件的信息
- <parent>
- <groupId>org.springframework.bootgroupId>
- <artifactId>spring-boot-starter-parentartifactId>
- <version>2.7.3version>
- <relativePath/>
- parent>
- <parent>
- <groupId>org.springframework.bootgroupId>
- <artifactId>spring-boot-dependenciesartifactId>
- <version>2.7.3version>
- parent>
- <groupId>org.springframework.bootgroupId>
- <artifactId>spring-boot-dependenciesartifactId>
- <version>2.7.3version>
- <packaging>pompackaging>
- <name>spring-boot-dependenciesname>
- <licenses>
- <license>
- <name>Apache License, Version 2.0name>
- <url>https://www.apache.org/licenses/LICENSE-2.0url>
- license>
- licenses>
6 第一次小的总结:spring-boot-dependencies 帮我们管理了SpringBoot开发环境中应用中所有应用中所有的依赖版本,解决了第三方库的冲突问题。
因此:spring-boot-dependencies称为 SpringBoot版本仲裁中心。
7 启动器的概念: spring-boot-starter-xxx 简称为启动器
启动器:说白了又是SpringBoot的启动场景
比如 spring-boot-starter-web,他又会导入所有的web环境所有的依赖
8 springboot官网介绍的应用场景的地址 在下面
https://docs.spring.io/spring-boot/docs/current/reference/html/dependency-versions.html#appendix.dependency-versions
9 下面是一些Springboot应用场景在官网中找到的
spring-boot-starter-test | 起动器测试弹簧启动应用程序和库包括JUnit木星,Hamcrest和5 |
spring-boot-starter-thymeleaf | 起动器构建MVC web应用程序使用Thymeleaf视图 |
spring-boot-starter-validation | 起动器与Hibernate验证框架的使用Java Bean验证 |
spring-boot-starter-web | 为构建web起动器,包括RESTful,使用Spring MVC应用程序。 使用Tomcat作为默认嵌入式容器 |
spring-boot-starter-web-services | 起动器使用Spring Web服务 |
spring-boot-starter-webflux | 起动器构建WebFlux应用程序使用Spring框架的反应网络的支持 |
spring-boot-starter-websocket | 起动器来构建使用Spring框架的WebSocket支持WebSocket应用程序 |

-
- /**
- * @ SpringBootApplication 标注的是一个SpringBoot的应用
- */
- @SpringBootApplication //标记成SpringBoot启动类 启动类下面所有的包
-
- public class Application {
- public static void main(String[] args) {
- //将SpringBoot应用启动
- //SpringApplication 类
- //run方法
- SpringApplication.run(Application.class,args);
- }
- }
-
- package org.springframework.boot;
-
-
-
- public class SpringApplication {
- public static final String BANNER_LOCATION_PROPERTY_VALUE = "banner.txt";
- public static final String BANNER_LOCATION_PROPERTY = "spring.banner.location";
- private static final String SYSTEM_PROPERTY_JAVA_AWT_HEADLESS = "java.awt.headless";
- private static final Log logger = LogFactory.getLog(SpringApplication.class);
- static final SpringApplicationShutdownHook shutdownHook = new SpringApplicationShutdownHook();
-
-
- package org.springframework.boot;
-
-
- public class SpringApplication {
- public static final String BANNER_LOCATION_PROPERTY_VALUE = "banner.txt";
- public static final String BANNER_LOCATION_PROPERTY = "spring.banner.location";
- private static final String SYSTEM_PROPERTY_JAVA_AWT_HEADLESS = "java.awt.headless";
- private static final Log logger = LogFactory.getLog(SpringApplication.class);
- static final SpringApplicationShutdownHook shutdownHook = new SpringApplicationShutdownHook();
- private Set
> primarySources; - private Set
sources; - private Class> mainApplicationClass;
- private Mode bannerMode;
- private boolean logStartupInfo;
- public static ConfigurableApplicationContext run(Class>[] primarySources, String[] args) {
- return (new SpringApplication(primarySources)).run(args);
- }
这个类主要做了以下四件事情

- package com.java.controller.com.java;
-
- import org.springframework.boot.SpringApplication;
- import org.springframework.boot.autoconfigure.SpringBootApplication;
-
- // @SpringBootApplication SpringBoot启动类(入口)
- //@Configuration Spring.xml 页是配置类
- //ComponentScan =
扫描包名 - //Spring底层在解析配置类:回去解析@ComponentScan,读取basePackage
- //如果没有读取到,会将当前配置类所在的包当成扫描包 package com.java.controller.com.java;
- //位置:最好放在需要扫描的包的根目录下面,或者说放在所有Bean的项目中
-
- /**
- * @ SpringBootApplication 标注的是一个SpringBoot的应用
- */
- @SpringBootApplication //标记成SpringBoot启动类 启动类下面所有的包
-
- public class Application {
- public static void main(String[] args) {
- //将SpringBoot应用启动
- //SpringApplication 类
- //run方法
- SpringApplication.run(Application.class,args);
- }
- }
- package org.springframework.boot.autoconfigure;
-
- @Target({ElementType.TYPE})
- @Retention(RetentionPolicy.RUNTIME)
- @Documented
- @Inherited
- @SpringBootConfiguration
- @EnableAutoConfiguration
- @ComponentScan(
- excludeFilters = {@Filter(
- type = FilterType.CUSTOM,
- classes = {TypeExcludeFilter.class}
- ), @Filter(
- type = FilterType.CUSTOM,
- classes = {AutoConfigurationExcludeFilter.class}
- )}
- )

-
- package org.springframework.boot;
-
-
- @Target({ElementType.TYPE})
- @Retention(RetentionPolicy.RUNTIME)
- @Documented
- @Configuration
- @Indexed
- public @interface SpringBootConfiguration {
- @AliasFor(
- annotation = Configuration.class
- )
- boolean proxyBeanMethods() default true;
- }
-
-
- package org.springframework.context.annotation;
-
- @Target({ElementType.TYPE})
- @Retention(RetentionPolicy.RUNTIME)
- @Documented
- @Component
- public @interface Configuration {
- @AliasFor(
- annotation = Component.class
- )
- String value() default "";
-
- boolean proxyBeanMethods() default true;
- }
- //
- // Source code recreated from a .class file by IntelliJ IDEA
- // (powered by Fernflower decompiler)
- //
-
- package org.springframework.context.annotation;
-
- @Target({ElementType.TYPE})
- @Retention(RetentionPolicy.RUNTIME)
- @Documented
- @Component
- public @interface Configuration {
- @AliasFor(
- annotation = Component.class
- )
- String value() default "";
-
- boolean proxyBeanMethods() default true;
- }

- @Target({ElementType.TYPE})
- @Retention(RetentionPolicy.RUNTIME)
- @Documented
- @Inherited
- @SpringBootConfiguration
- @EnableAutoConfiguration
- @ComponentScan(
- excludeFilters = {@Filter(
- type = FilterType.CUSTOM,
- classes = {TypeExcludeFilter.class}
- ), @Filter(
- type = FilterType.CUSTOM,
- classes = {AutoConfigurationExcludeFilter.class}
- )}
- @Target({ElementType.TYPE})
- @Retention(RetentionPolicy.RUNTIME)
- @Documented
- @Inherited
- @AutoConfigurationPackage
- @Import({AutoConfigurationImportSelector.class})
- public @interface EnableAutoConfiguration {
- String ENABLED_OVERRIDE_PROPERTY = "spring.boot.enableautoconfiguration";
-
- Class>[] exclude() default {};
-
- String[] excludeName() default {};
- }
- //
- // Source code recreated from a .class file by IntelliJ IDEA
- // (powered by Fernflower decompiler)
- //
-
- package org.springframework.boot.autoconfigure;
-
- import java.lang.annotation.Documented;
- import java.lang.annotation.ElementType;
- import java.lang.annotation.Inherited;
- import java.lang.annotation.Retention;
- import java.lang.annotation.RetentionPolicy;
- import java.lang.annotation.Target;
- import org.springframework.boot.autoconfigure.AutoConfigurationPackages.Registrar;
- import org.springframework.context.annotation.Import;
-
- @Target({ElementType.TYPE})
- @Retention(RetentionPolicy.RUNTIME)
- @Documented
- @Inherited
- @Import({Registrar.class})
- public @interface AutoConfigurationPackage {
- String[] basePackages() default {};
-
- Class>[] basePackageClasses() default {};
- }
-
-
- package org.springframework.boot.autoconfigure;
-
-
- @Target({ElementType.TYPE})
- @Retention(RetentionPolicy.RUNTIME)
- @Documented
- @Inherited
- @AutoConfigurationPackage
- @Import({AutoConfigurationImportSelector.class})
- public @interface EnableAutoConfiguration {
- String ENABLED_OVERRIDE_PROPERTY = "spring.boot.enableautoconfiguration";
-
- Class>[] exclude() default {};
-
- String[] excludeName() default {};
- }

- package org.springframework.boot.autoconfigure;
-
-
-
- public class AutoConfigurationImportSelector implements DeferredImportSelector, BeanClassLoaderAware, ResourceLoaderAware, BeanFactoryAware, EnvironmentAware, Ordered {
- private static final AutoConfigurationImportSelector.AutoConfigurationEntry EMPTY_ENTRY = new AutoConfigurationImportSelector.AutoConfigurationEntry();
- private static final String[] NO_IMPORTS = new String[0];
- private static final Log logger = LogFactory.getLog(AutoConfigurationImportSelector.class);
- private static final String PROPERTY_NAME_AUTOCONFIGURE_EXCLUDE = "spring.autoconfigure.exclude";
- private ConfigurableListableBeanFactory beanFactory;
- private Environment environment;
- private ClassLoader beanClassLoader;
- private ResourceLoader resourceLoader;
- private AutoConfigurationImportSelector.ConfigurationClassFilter configurationClassFilter;
-
- public AutoConfigurationImportSelector() {
- }

- protected AutoConfigurationImportSelector.AutoConfigurationEntry getAutoConfigurationEntry(AnnotationMetadata annotationMetadata) {
- if (!this.isEnabled(annotationMetadata)) {
- return EMPTY_ENTRY;
- } else {
- AnnotationAttributes attributes = this.getAttributes(annotationMetadata);
- List
configurations = this.getCandidateConfigurations(annotationMetadata, attributes); - configurations = this.removeDuplicates(configurations);
- Set
exclusions = this.getExclusions(annotationMetadata, attributes); - this.checkExcludedClasses(configurations, exclusions);
- configurations.removeAll(exclusions);
- configurations = this.getConfigurationClassFilter().filter(configurations);
- this.fireAutoConfigurationImportEvents(configurations, exclusions);
- return new AutoConfigurationImportSelector.AutoConfigurationEntry(configurations, exclusions);
- }
- }

- protected List
getCandidateConfigurations(AnnotationMetadata metadata, AnnotationAttributes attributes) { - List
configurations = new ArrayList(SpringFactoriesLoader.loadFactoryNames(this.getSpringFactoriesLoaderFactoryClass(), this.getBeanClassLoader())); - ImportCandidates.load(AutoConfiguration.class, this.getBeanClassLoader()).forEach(configurations::add);
- Assert.notEmpty(configurations, "No auto configuration classes found in META-INF/spring.factories nor in META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports. If you are using a custom packaging, make sure that file is correct.");
- return configurations;
- }
- protected Class> getSpringFactoriesLoaderFactoryClass() {
- return EnableAutoConfiguration.class;
- }


- public static List
loadFactoryNames(Class> factoryType, @Nullable ClassLoader classLoader) { - ClassLoader classLoaderToUse = classLoader;
- if (classLoader == null) {
- classLoaderToUse = SpringFactoriesLoader.class.getClassLoader();
- }
-
- String factoryTypeName = factoryType.getName();
- return (List)loadSpringFactories(classLoaderToUse).getOrDefault(factoryTypeName, Collections.emptyList());
- }

- public final class SpringFactoriesLoader {
- public static final String FACTORIES_RESOURCE_LOCATION = "META-INF/spring.factories";
- private static final Log logger = LogFactory.getLog(SpringFactoriesLoader.class);
- static final Map
>> cache = new ConcurrentReferenceHashMap(); -
- private SpringFactoriesLoader() {
- }
- protected List
getCandidateConfigurations(AnnotationMetadata metadata, AnnotationAttributes attributes) { - List
configurations = new ArrayList(SpringFactoriesLoader.loadFactoryNames(this.getSpringFactoriesLoaderFactoryClass(), this.getBeanClassLoader())); - ImportCandidates.load(AutoConfiguration.class, this.getBeanClassLoader()).forEach(configurations::add);
- Assert.notEmpty(configurations, "No auto configuration classes found in META-INF/spring.factories nor in META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports. If you are using a custom packaging, make sure that file is correct.");
- return configurations;
- }
- private static Map
> loadSpringFactories(ClassLoader classLoader) { - Map
> result = (Map)cache.get(classLoader); - if (result != null) {
- return result;
- } else {
- HashMap result = new HashMap();
-
- try {
- Enumeration urls = classLoader.getResources("META-INF/spring.factories");
-
- 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 factoryTypeName = ((String)entry.getKey()).trim();
- String[] factoryImplementationNames = StringUtils.commaDelimitedListToStringArray((String)entry.getValue());
- String[] var10 = factoryImplementationNames;
- int var11 = factoryImplementationNames.length;
-
- for(int var12 = 0; var12 < var11; ++var12) {
- String factoryImplementationName = var10[var12];
- ((List)result.computeIfAbsent(factoryTypeName, (key) -> {
- return new ArrayList();
- })).add(factoryImplementationName.trim());
- }
- }
- }
