面试必备,个人整理极简springboot原理(只包含大致流程)

简介: 使用spring boot的时候直接在application.properties中配置就可以了,但是具体原理是什么呢。


image.png

使用spring boot的时候直接在application.properties中配置就可以了,但是具体原理是什么呢。

1. @SpringBootApplication
2. public class DemoApplication {
3. 
4.  public static void main(String[] args) {
5.    SpringApplication.run(DemoApplication.class, args);
6.  }
7. }

1.源码解析

首先springboot提供了一个application类,这个类提供了一个注解@SpringBootApplication。

1. @Target({ElementType.TYPE})
2. @Retention(RetentionPolicy.RUNTIME)
3. @Documented
4. @Inherited
5. @SpringBootConfiguration
6. @EnableAutoConfiguration
7. @ComponentScan(
8.     excludeFilters = {@Filter(
9.     type = FilterType.CUSTOM,
10.     classes = {TypeExcludeFilter.class}
11. ), @Filter(
12.     type = FilterType.CUSTOM,
13.     classes = {AutoConfigurationExcludeFilter.class}
14. )}
15. )
16. public @interface SpringBootApplication {
17.     @AliasFor(
18.         annotation = EnableAutoConfiguration.class
19.     )
20.     .
21.     .
22.     .
23. }

我们点击进去看到SpringBootApplication 类,然后点击@EnableAutoConfiguration注解进入。

1. @Target({ElementType.TYPE})
2. @Retention(RetentionPolicy.RUNTIME)
3. @Documented
4. @Inherited
5. @AutoConfigurationPackage
6. @Import({AutoConfigurationImportSelector.class})
7. public @interface EnableAutoConfiguration {
8. String ENABLED_OVERRIDE_PROPERTY = "spring.boot.enableautoconfiguration";
9. 
10.     Class<?>[] exclude() default {};
11. 
12.     String[] excludeName() default {};
13. }

然后在点击@AutoConfigurationPackage进入,然后找到getCandidateConfigurations方法可以看到SpringFactoriesLoader.loadFactoryNames,根据注释可以看到,方法用于寻找带有META-INF/spring.factories的包。也可以看看这个方法的实现

1. protected List<String> getCandidateConfigurations(AnnotationMetadata metadata, AnnotationAttributes attributes) {
2. List<String> configurations = SpringFactoriesLoader.loadFactoryNames(this.getSpringFactoriesLoaderFactoryClass(), this.getBeanClassLoader());
3. Assert.notEmpty(configurations, "No auto configuration classes found in META-INF/spring.factories. If you are using a custom packaging, make sure that file is correct.");
4. return configurations;
5.     }

SpringFactoriesLoader.loadFactoryNames实现

1. public static List<String> loadFactoryNames(Class<?> factoryClass, @Nullable ClassLoader classLoader) {
2. String factoryClassName = factoryClass.getName();
3. return (List)loadSpringFactories(classLoader).getOrDefault(factoryClassName, Collections.emptyList());
4.     }
5. 
6. private static Map<String, List<String>> loadSpringFactories(@Nullable ClassLoader classLoader) {
7.         MultiValueMap<String, String> result = (MultiValueMap)cache.get(classLoader);
8. if (result != null) {
9. return result;
10.         } else {
11. try {
12.                 Enumeration<URL> urls = classLoader != null ? classLoader.getResources("META-INF/spring.factories") : ClassLoader.getSystemResources("META-INF/spring.factories");
13.                 LinkedMultiValueMap result = new LinkedMultiValueMap();
14. 
15. while(urls.hasMoreElements()) {
16.                     URL url = (URL)urls.nextElement();
17.                     UrlResource resource = new UrlResource(url);
18.                     Properties properties = PropertiesLoaderUtils.loadProperties(resource);
19. Iterator var6 = properties.entrySet().iterator();
20. 
21. while(var6.hasNext()) {
22.                         Entry<?, ?> entry = (Entry)var6.next();
23. String factoryClassName = ((String)entry.getKey()).trim();
24. String[] var9 = StringUtils.commaDelimitedListToStringArray((String)entry.getValue());
25. int var10 = var9.length;
26. 
27. for(int var11 = 0; var11 < var10; ++var11) {
28. String factoryName = var9[var11];
29.                             result.add(factoryClassName, factoryName.trim());
30.                         }
31.                     }
32.                 }
33. 
34.                 cache.put(classLoader, result);
35. return result;
36.             } catch (IOException var13) {
37. throw new IllegalArgumentException("Unable to load factories from location [META-INF/spring.factories]", var13);
38.             }
39.         }
40.     }

然后会找到所有带有META-INF/spring.factories的包,我们选择spring -boot -autoconfigur包,因为他有spring.factories。

image.png

打开spring.factories 我们看到各种配置,是不是有些眼熟,貌似包括了大部分使用的技术。

1. # Initializers
2. org.springframework.context.ApplicationContextInitializer=\
3. org.springframework.boot.autoconfigure.SharedMetadataReaderFactoryContextInitializer,\
4. org.springframework.boot.autoconfigure.logging.ConditionEvaluationReportLoggingListener
5. 
6. # Application Listeners
7. org.springframework.context.ApplicationListener=\
8. org.springframework.boot.autoconfigure.BackgroundPreinitializer
9. 
10. # Auto Configuration Import Listeners
11. org.springframework.boot.autoconfigure.AutoConfigurationImportListener=\
12. org.springframework.boot.autoconfigure.condition.ConditionEvaluationReportAutoConfigurationImportListener
13. 
14. # Auto Configuration Import Filters
15. org.springframework.boot.autoconfigure.AutoConfigurationImportFilter=\
16. org.springframework.boot.autoconfigure.condition.OnBeanCondition,\
17. org.springframework.boot.autoconfigure.condition.OnClassCondition,\
18. org.springframework.boot.autoconfigure.condition.OnWebApplicationCondition
19. 
20. # Auto Configure
21. org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
22. org.springframework.boot.autoconfigure.admin.SpringApplicationAdminJmxAutoConfiguration,\
23. org.springframework.boot.autoconfigure.aop.AopAutoConfiguration,\
24. org.springframework.boot.autoconfigure.amqp.RabbitAutoConfiguration,\
25. org.springframework.boot.autoconfigure.batch.BatchAutoConfiguration,\
26. org.springframework.boot.autoconfigure.cache.CacheAutoConfiguration,\
27. org.springframework.boot.autoconfigure.cassandra.CassandraAutoConfiguration,\
28. org.springframework.boot.autoconfigure.cloud.CloudServiceConnectorsAutoConfiguration,\
29. org.springframework.boot.autoconfigure.context.ConfigurationPropertiesAutoConfiguration,\
30. org.springframework.boot.autoconfigure.context.MessageSourceAutoConfiguration,\
31. org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration,\
32. org.springframework.boot.autoconfigure.couchbase.CouchbaseAutoConfiguration,\
33. org.springframework.boot.autoconfigure.dao.PersistenceExceptionTranslationAutoConfiguration,\
34. org.springframework.boot.autoconfigure.data.cassandra.CassandraDataAutoConfiguration,\
35. org.springframework.boot.autoconfigure.data.cassandra.CassandraReactiveDataAutoConfiguration,\
36. org.springframework.boot.autoconfigure.data.cassandra.CassandraReactiveRepositoriesAutoConfiguration,\
37. org.springframework.boot.autoconfigure.data.cassandra.CassandraRepositoriesAutoConfiguration,\
38. org.springframework.boot.autoconfigure.data.couchbase.CouchbaseDataAutoConfiguration,\
39. org.springframework.boot.autoconfigure.data.couchbase.CouchbaseReactiveDataAutoConfiguration,\
40. org.springframework.boot.autoconfigure.data.couchbase.CouchbaseReactiveRepositoriesAutoConfiguration,\
41. org.springframework.boot.autoconfigure.data.couchbase.CouchbaseRepositoriesAutoConfiguration,\
42. org.springframework.boot.autoconfigure.data.elasticsearch.ElasticsearchAutoConfiguration,\
43. org.springframework.boot.autoconfigure.data.elasticsearch.ElasticsearchDataAutoConfiguration,\
44. org.springframework.boot.autoconfigure.data.elasticsearch.ElasticsearchRepositoriesAutoConfiguration,\
45. org.springframework.boot.autoconfigure.data.jdbc.JdbcRepositoriesAutoConfiguration,\
46. org.springframework.boot.autoconfigure.data.jpa.JpaRepositoriesAutoConfiguration,\
47. org.springframework.boot.autoconfigure.data.ldap.LdapRepositoriesAutoConfiguration,\
48. org.springframework.boot.autoconfigure.data.mongo.MongoDataAutoConfiguration,\
49. org.springframework.boot.autoconfigure.data.mongo.MongoReactiveDataAutoConfiguration,\
50. org.springframework.boot.autoconfigure.data.mongo.MongoReactiveRepositoriesAutoConfiguration,\
51. org.springframework.boot.autoconfigure.data.mongo.MongoRepositoriesAutoConfiguration,\
52. org.springframework.boot.autoconfigure.data.neo4j.Neo4jDataAutoConfiguration,\
53. org.springframework.boot.autoconfigure.data.neo4j.Neo4jRepositoriesAutoConfiguration,\
54. org.springframework.boot.autoconfigure.data.solr.SolrRepositoriesAutoConfiguration,\
55. org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration,\
56. org.springframework.boot.autoconfigure.data.redis.RedisReactiveAutoConfiguration,\
57. org.springframework.boot.autoconfigure.data.redis.RedisRepositoriesAutoConfiguration,\
58. org.springframework.boot.autoconfigure.data.rest.RepositoryRestMvcAutoConfiguration,\
59. org.springframework.boot.autoconfigure.data.web.SpringDataWebAutoConfiguration,\
60. org.springframework.boot.autoconfigure.elasticsearch.jest.JestAutoConfiguration,\
61. org.springframework.boot.autoconfigure.elasticsearch.rest.RestClientAutoConfiguration,\
62. org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration,\
63. org.springframework.boot.autoconfigure.freemarker.FreeMarkerAutoConfiguration,\
64. org.springframework.boot.autoconfigure.gson.GsonAutoConfiguration,\
65. org.springframework.boot.autoconfigure.h2.H2ConsoleAutoConfiguration,\
66. org.springframework.boot.autoconfigure.hateoas.HypermediaAutoConfiguration,\
67. org.springframework.boot.autoconfigure.hazelcast.HazelcastAutoConfiguration,\
68. org.springframework.boot.autoconfigure.hazelcast.HazelcastJpaDependencyAutoConfiguration,\
69. org.springframework.boot.autoconfigure.http.HttpMessageConvertersAutoConfiguration,\
70. org.springframework.boot.autoconfigure.http.codec.CodecsAutoConfiguration,\
71. org.springframework.boot.autoconfigure.influx.InfluxDbAutoConfiguration,\
72. org.springframework.boot.autoconfigure.info.ProjectInfoAutoConfiguration,\
73. org.springframework.boot.autoconfigure.integration.IntegrationAutoConfiguration,\
74. org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration,\
75. org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration,\
76. org.springframework.boot.autoconfigure.jdbc.JdbcTemplateAutoConfiguration,\
77. org.springframework.boot.autoconfigure.jdbc.JndiDataSourceAutoConfiguration,\
78. org.springframework.boot.autoconfigure.jdbc.XADataSourceAutoConfiguration,\
79. org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration,\
80. org.springframework.boot.autoconfigure.jms.JmsAutoConfiguration,\
81. org.springframework.boot.autoconfigure.jmx.JmxAutoConfiguration,\
82. org.springframework.boot.autoconfigure.jms.JndiConnectionFactoryAutoConfiguration,\
83. org.springframework.boot.autoconfigure.jms.activemq.ActiveMQAutoConfiguration,\
84. org.springframework.boot.autoconfigure.jms.artemis.ArtemisAutoConfiguration,\
85. org.springframework.boot.autoconfigure.groovy.template.GroovyTemplateAutoConfiguration,\
86. org.springframework.boot.autoconfigure.jersey.JerseyAutoConfiguration,\
87. org.springframework.boot.autoconfigure.jooq.JooqAutoConfiguration,\
88. org.springframework.boot.autoconfigure.jsonb.JsonbAutoConfiguration,\
89. org.springframework.boot.autoconfigure.kafka.KafkaAutoConfiguration,\
90. org.springframework.boot.autoconfigure.ldap.embedded.EmbeddedLdapAutoConfiguration,\
91. org.springframework.boot.autoconfigure.ldap.LdapAutoConfiguration,\
92. org.springframework.boot.autoconfigure.liquibase.LiquibaseAutoConfiguration,\
93. org.springframework.boot.autoconfigure.mail.MailSenderAutoConfiguration,\
94. org.springframework.boot.autoconfigure.mail.MailSenderValidatorAutoConfiguration,\
95. org.springframework.boot.autoconfigure.mongo.embedded.EmbeddedMongoAutoConfiguration,\
96. org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration,\
97. org.springframework.boot.autoconfigure.mongo.MongoReactiveAutoConfiguration,\
98. org.springframework.boot.autoconfigure.mustache.MustacheAutoConfiguration,\
99. org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration,\
100. org.springframework.boot.autoconfigure.quartz.QuartzAutoConfiguration,\
101. org.springframework.boot.autoconfigure.reactor.core.ReactorCoreAutoConfiguration,\
102. org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration,\
103. org.springframework.boot.autoconfigure.security.servlet.SecurityRequestMatcherProviderAutoConfiguration,\
104. org.springframework.boot.autoconfigure.security.servlet.UserDetailsServiceAutoConfiguration,\
105. org.springframework.boot.autoconfigure.security.servlet.SecurityFilterAutoConfiguration,\
106. org.springframework.boot.autoconfigure.security.reactive.ReactiveSecurityAutoConfiguration,\
107. org.springframework.boot.autoconfigure.security.reactive.ReactiveUserDetailsServiceAutoConfiguration,\
108. org.springframework.boot.autoconfigure.sendgrid.SendGridAutoConfiguration,\
109. org.springframework.boot.autoconfigure.session.SessionAutoConfiguration,\
110. org.springframework.boot.autoconfigure.security.oauth2.client.servlet.OAuth2ClientAutoConfiguration,\
111. org.springframework.boot.autoconfigure.security.oauth2.client.reactive.ReactiveOAuth2ClientAutoConfiguration,\
112. org.springframework.boot.autoconfigure.security.oauth2.resource.servlet.OAuth2ResourceServerAutoConfiguration,\
113. org.springframework.boot.autoconfigure.security.oauth2.resource.reactive.ReactiveOAuth2ResourceServerAutoConfiguration,\
114. org.springframework.boot.autoconfigure.solr.SolrAutoConfiguration,\
115. org.springframework.boot.autoconfigure.task.TaskExecutionAutoConfiguration,\
116. org.springframework.boot.autoconfigure.task.TaskSchedulingAutoConfiguration,\
117. org.springframework.boot.autoconfigure.thymeleaf.ThymeleafAutoConfiguration,\
118. org.springframework.boot.autoconfigure.transaction.TransactionAutoConfiguration,\
119. org.springframework.boot.autoconfigure.transaction.jta.JtaAutoConfiguration,\
120. org.springframework.boot.autoconfigure.validation.ValidationAutoConfiguration,\
121. org.springframework.boot.autoconfigure.web.client.RestTemplateAutoConfiguration,\
122. org.springframework.boot.autoconfigure.web.embedded.EmbeddedWebServerFactoryCustomizerAutoConfiguration,\
123. org.springframework.boot.autoconfigure.web.reactive.HttpHandlerAutoConfiguration,\
124. org.springframework.boot.autoconfigure.web.reactive.ReactiveWebServerFactoryAutoConfiguration,\
125. org.springframework.boot.autoconfigure.web.reactive.WebFluxAutoConfiguration,\
126. org.springframework.boot.autoconfigure.web.reactive.error.ErrorWebFluxAutoConfiguration,\
127. org.springframework.boot.autoconfigure.web.reactive.function.client.ClientHttpConnectorAutoConfiguration,\
128. org.springframework.boot.autoconfigure.web.reactive.function.client.WebClientAutoConfiguration,\
129. org.springframework.boot.autoconfigure.web.servlet.DispatcherServletAutoConfiguration,\
130. org.springframework.boot.autoconfigure.web.servlet.ServletWebServerFactoryAutoConfiguration,\
131. org.springframework.boot.autoconfigure.web.servlet.error.ErrorMvcAutoConfiguration,\
132. org.springframework.boot.autoconfigure.web.servlet.HttpEncodingAutoConfiguration,\
133. org.springframework.boot.autoconfigure.web.servlet.MultipartAutoConfiguration,\
134. org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration,\
135. org.springframework.boot.autoconfigure.websocket.reactive.WebSocketReactiveAutoConfiguration,\
136. org.springframework.boot.autoconfigure.websocket.servlet.WebSocketServletAutoConfiguration,\
137. org.springframework.boot.autoconfigure.websocket.servlet.WebSocketMessagingAutoConfiguration,\
138. org.springframework.boot.autoconfigure.webservices.WebServicesAutoConfiguration,\
139. org.springframework.boot.autoconfigure.webservices.client.WebServiceTemplateAutoConfiguration
140. 
141. # Failure analyzers
142. org.springframework.boot.diagnostics.FailureAnalyzer=\
143. org.springframework.boot.autoconfigure.diagnostics.analyzer.NoSuchBeanDefinitionFailureAnalyzer,\
144. org.springframework.boot.autoconfigure.jdbc.DataSourceBeanCreationFailureAnalyzer,\
145. org.springframework.boot.autoconfigure.jdbc.HikariDriverConfigurationFailureAnalyzer,\
146. org.springframework.boot.autoconfigure.session.NonUniqueSessionRepositoryFailureAnalyzer
147. 
148. # Template availability providers
149. org.springframework.boot.autoconfigure.template.TemplateAvailabilityProvider=\
150. org.springframework.boot.autoconfigure.freemarker.FreeMarkerTemplateAvailabilityProvider,\
151. org.springframework.boot.autoconfigure.mustache.MustacheTemplateAvailabilityProvider,\
152. org.springframework.boot.autoconfigure.groovy.template.GroovyTemplateAvailabilityProvider,\
153. org.springframework.boot.autoconfigure.thymeleaf.ThymeleafTemplateAvailabilityProvider,\
154. org.springframework.boot.autoconfigure.web.servlet.JspTemplateAvailabilityProvider

然后我们随便找一个左键打开这里打开MongoAutoConfiguration,我们可以看到。

1. @Configuration
2. @ConditionalOnClass({MongoClient.class})
3. @EnableConfigurationProperties({MongoProperties.class})
4. @ConditionalOnMissingBean(
5.     type = {"org.springframework.data.mongodb.MongoDbFactory"}
6. )
7. public class MongoAutoConfiguration {
8. private final MongoClientOptions options;
9. private final MongoClientFactory factory;
10. private MongoClient mongo;
11. 
12. public MongoAutoConfiguration(MongoProperties properties, ObjectProvider<MongoClientOptions> options, Environment environment) {
13. this.options = (MongoClientOptions)options.getIfAvailable();
14. this.factory = new MongoClientFactory(properties, environment);
15.     }
16. 
17.     .
18.     .
19.     .
20. }

@ConditionalOnClass({MongoClient.class}) 是存在MongoClient.class时候自动配置

@ConditionalOnMissingBean(

    type = {"org.springframework.data.mongodb.MongoDbFactory"}

)  不存在时候自动配置

@EnableConfigurationProperties({MongoProperties.class}) 打开这个类,可以看到。

1. @ConfigurationProperties(
2.     prefix = "spring.data.mongodb"
3. )
4. public class MongoProperties {
5. public static final int DEFAULT_PORT = 27017;
6. public static final String DEFAULT_URI = "mongodb://localhost/test";
7. private String host;
8. private Integer port = null;
9. private String uri;
10. private String database;
11. private String authenticationDatabase;
12. private String gridFsDatabase;
13. private String username;
14. private char[] password;
15. private Class<?> fieldNamingStrategy;
16. 
17. public MongoProperties() {
18.    .
19.    .
20.    .
21. }

@ConfigurationProperties(

    prefix = "spring.data.mongodb"

)是从application.properties中获取配置 。

这样spring boot就可以自动配置了。


相关实践学习
以电商场景为例搭建AI语义搜索应用
本实验旨在通过阿里云Elasticsearch结合阿里云搜索开发工作台AI模型服务,构建一个高效、精准的语义搜索系统,模拟电商场景,深入理解AI搜索技术原理并掌握其实现过程。
ElasticSearch 最新快速入门教程
本课程由千锋教育提供。全文搜索的需求非常大。而开源的解决办法Elasricsearch(Elastic)就是一个非常好的工具。目前是全文搜索引擎的首选。本系列教程由浅入深讲解了在CentOS7系统下如何搭建ElasticSearch,如何使用Kibana实现各种方式的搜索并详细分析了搜索的原理,最后讲解了在Java应用中如何集成ElasticSearch并实现搜索。 &nbsp;
相关文章
|
4月前
|
人工智能 Java 开发者
【Spring】原理解析:Spring Boot 自动配置
Spring Boot通过“约定优于配置”的设计理念,自动检测项目依赖并根据这些依赖自动装配相应的Bean,从而解放开发者从繁琐的配置工作中解脱出来,专注于业务逻辑实现。
1525 0
|
6月前
|
Java Spring 容器
SpringBoot自动配置的原理是什么?
Spring Boot自动配置核心在于@EnableAutoConfiguration注解,它通过@Import导入配置选择器,加载META-INF/spring.factories中定义的自动配置类。这些类根据@Conditional系列注解判断是否生效。但Spring Boot 3.0后已弃用spring.factories,改用新格式的.imports文件进行配置。
1019 0
|
3月前
|
XML JSON Java
【SpringBoot(三)】从请求到响应再到视图解析与模板引擎,本文带你领悟SpringBoot请求接收全流程!
Springboot专栏第三章,从请求的接收到视图解析,再到thymeleaf模板引擎的使用! 本文带你领悟SpringBoot请求接收到渲染的使用全流程!
281 3
|
3月前
|
JavaScript Java Maven
【SpringBoot(二)】带你认识Yaml配置文件类型、SpringMVC的资源访问路径 和 静态资源配置的原理!
SpringBoot专栏第二章,从本章开始正式进入SpringBoot的WEB阶段开发,本章先带你认识yaml配置文件和资源的路径配置原理,以方便在后面的文章中打下基础
363 3
|
3月前
|
XML Java 应用服务中间件
【SpringBoot(一)】Spring的认知、容器功能讲解与自动装配原理的入门,带你熟悉Springboot中基本的注解使用
SpringBoot专栏开篇第一章,讲述认识SpringBoot、Bean容器功能的讲解、自动装配原理的入门,还有其他常用的Springboot注解!如果想要了解SpringBoot,那么就进来看看吧!
464 2
|
6月前
|
前端开发 Java 数据库连接
SpringBoot参数校验底层原理和实操。深度历险、深度解析(图解+秒懂+史上最全)
SpringBoot参数校验底层原理和实操。深度历险、深度解析(图解+秒懂+史上最全)
SpringBoot参数校验底层原理和实操。深度历险、深度解析(图解+秒懂+史上最全)
|
10月前
|
Java Spring
SpringBoot自动配置原理
本文深入解析了SpringBoot的核心功能——自动配置,重点探讨了`org.springframework.boot.autoconfigure`及相关注解的工作机制。通过分析`@SpringBootApplication`、`@EnableAutoConfiguration`等注解,揭示了SpringBoot如何基于类路径和条件自动装配Bean
495 8
|
10月前
|
Java
SpringBoot启动流程
springboot项目在启动的时候, 首先会执行启动引导类里面的SpringApplication.run(AdminApplication.class, args)方法 这个run方法主要做的事情可以分为三个部分 : 第一部分进行SpringApplication的初始化模块,配置一些基本的环境变量、资源、构造器、监听器 第二部分实现了应用具体的启动方案,包括启动流程的监听模块、加载配置环境模块、及核心的创建上下文环境模块 第三部分是自动化配置模块,该模块作为springboot自动配置核心,在后面的分析中会详细讨论
|
10月前
|
Java
SpringBoot自动装配的原理
在SpringBoot项目的启动引导类上都有一个注解@SpringBootApplication 这个注解是一个复合注解, 其中有三个注解构成 , 分别是 ● @SpringBootConfiguration : 是@Configuration的派生注解 , 标注当前类是一个SpringBoot的配置类 ● @ComponentScan : 开启组件扫描, 默认扫描的是当前启动引导了所在包以及子包 ● @EnableAutoConfiguration : 开启自动配置(自动配置核心注解) 2.在@EnableAutoConfiguration注解的内容使用@Import注解导入了一个AutoC
|
10月前
|
JavaScript 前端开发 Java
Idea启动SpringBoot程序报错:Veb server failed to start. Port 8082 was already in use;端口冲突的原理与解决方案
本文解决了Idea启动SpringBoot程序报错:Veb server failed to start. Port 8082 was already in use的问题,并通过介绍端口的使用原理和操作系统的端口管理机制,可以更有效地解决端口冲突问题,并确保Web服务器能够顺利启动和运行。 只有锻炼思维才能可持续地解决问题,只有思维才是真正值得学习和分享的核心要素。如果这篇博客能给您带来一点帮助,麻烦您点个赞支持一下,还可以收藏起来以备不时之需,有疑问和错误欢迎在评论区指出~