当前位置: 首页 > news >正文

SpringBoot的注解@SpringBootApplication及自动装配

目录

一、pom文件

二、@SpringBootApplication注解

1.@SpringBootApplication

2.@Configuration

3.这个启动类也可以被看成是一个配置类

三、@SpringBootApplication注解2

1.SpringBootConfiguration

2.@Configuration

3.@EnableAutoConfiguration!!!

4.@EnableAutoConfiguration2

5.@Import

6.@Import(EnableAutoConfigurationImportSelector.class)

打个断点debug看一下:

四、自动装配原理总结

1.第一件事

启动类也是一个配置类,why?

2.springBoot靠的是自动装配,自动装配说白了就是starter,这一个一个的starter替我完成了自动装配

3.父工程的依赖替我管理着所有的版本

4.所有的东西是怎么被加载到的?怎么被自动装配上的?

5.我到底应该装配哪些东西,靠什么?

(1)这些东西(springBoot这个版本所有的自动装配的类)在哪?

(2)可以看一下spring.factories

比如做文件上传:

点进去看:Multipart自动装配

自动装配的什么

 这里是有默认值的,可以改,在配置文件里改:

6.但是这些东西有很多个,我要根据我现在的pom文件的配置以及默认配置去筛查,会先筛查一部分,等什么时候再有了再导再去做自动装配

筛查

五.SpringBoot的热部署


一、pom文件

1.在SpringBoot中扫描注解等这些事情不用自己做了,核心根本是@SpringBootApplication这个注解,而这个注解来源于pom文件中的:

    <parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.7.4</version><relativePath/></parent>

2.这是一个父工程依赖,点进去:点进去之后里面还有一层

<parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-dependencies</artifactId><version>2.7.4</version>
</parent>

可以看出这个依赖是所有版本的父依赖

3.再点进去:

可以看到,所有的版本都在这里被管理着,所以在pom文件里不用写版本号,因为这里都写了

二、@SpringBootApplication注解

1.@SpringBootApplication

Spring Boot应用标注在某个类上说明这个类是SpringBoot的主配置类,SpringBoot就应该运行这个类的main方法来启动SpringBoot应用。

2.@Configuration

spring里面声明一个类是配置类用的注解是@Configuration;SpringBoot是约定>配置,配置本身就少,就一个配置文件,而且还变了样式,跟以前不一样,其他所有的东西原则上都应该靠注解,其次就是配置类,spring的时候可以将一个配置文件变成配置类,然后把所有配置文件的东西放到配置类里面

3.这个启动类也可以被看成是一个配置类

因为@SpringBootApplication注解里面有一个注解:@SpringBootConfiguration

@SpringBootConfiguration再往下走就是@Configuration

所以它的底层还是spring,所以这个类也可以被看成是一个配置类

三、@SpringBootApplication注解2

@SpringBootApplication注解进去:@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}
)}
)
public @interface SpringBootApplication {@SpringBootConfiguration注解再进去:@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Configuration
@Indexed
public @interface SpringBootConfiguration {@Configuration再进去:@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Component
public @interface Configuration {

1.SpringBootConfiguration

SpringBoot的配置类,标注在某个类上,表示这是一个Spring Boot的配置类

2.@Configuration

配置类上标注这个注解

配置类 ----- 配置文件;配置类也是容器中的一个组件;@Component(@Configuration进去就有这个@Component注解)

3.@EnableAutoConfiguration!!!

开启自动配置功能

以前我们需要配置的东西,现在Spring Boot帮我们自动配置;@EnableAutoConfiguration告诉SpringBoot开启自动配置功能;这样自动配置才能生效;-----------springBoot能帮我们完成很多装配的功能的原因

4.@EnableAutoConfiguration2

springBoot的自动装配靠的就是@EnableAutoConfiguration注解,@EnableAutoConfiguration告诉SpringBoot开启自动配置功能;这样自动配置才能生效

@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Inherited
@AutoConfigurationPackage
@Import({AutoConfigurationImportSelector.class})
public @interface EnableAutoConfiguration {

@EnableAutoConfiguration里面有一个功能:@Import,Import导入,导入哪些自动配置的选择器(AutoConfigurationImportSelector)

5.@Import

Spring的底层注解@Import,给容器中导入一个组件;导入的组件由AutoConfigurationPackages.Registrar.class;将主配置类(@SpringBootApplication标注的类)的所在包及下面所有子包里面的所有组件扫描到Spring容器

6.@Import(EnableAutoConfigurationImportSelector.class)

(1)给容器中导入组件?EnableAutoConfigurationImportSelector:导入哪些组件的选择器

(2)将所有需要导入的组件以全类名的方式返回;这些组件就会被添加到容器中;会给容器中导入非常多的自动配置类(xxxAutoConfiguration);就是给容器中导入这个场景需要的所有组件

(3)并配置好这些组件;

(4)按照现在这个代码依赖的情况一上来就是web的starter、测试的starter、还有默认的这些东西,其他的没有,那么就会把这两块筛查出来

<parent>(默认)<groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.7.4</version> <!-- 这里改成版本稍低点的 --><relativePath/> <!-- lookup parent from repository -->
</parent><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency>
</dependencies>

public class AutoConfigurationImportSelector implements DeferredImportSelector, BeanClassLoaderAware, ResourceLoaderAware, BeanFactoryAware, EnvironmentAware, Ordered {// 这里的参数 annotationMetadata,就是 @EnableAutoConfiguration 注解的元数据public String[] selectImports(AnnotationMetadata annotationMetadata) {if (!this.isEnabled(annotationMetadata)) {return NO_IMPORTS;} else {AutoConfigurationEntry autoConfigurationEntry = // 获取自动配置类this.getAutoConfigurationEntry(annotationMetadata);return StringUtils.toStringArray(autoConfigurationEntry.getConfigurations());}}protected static class AutoConfigurationEntry {private final List<String> configurations;	// 需要导入的private final Set<String> exclusions;		// 不需要导入的}protected AutoConfigurationEntry getAutoConfigurationEntry(AnnotationMetadata annotationMetadata) {if (!isEnabled(annotationMetadata)) {return EMPTY_ENTRY;}AnnotationAttributes attributes = getAttributes(annotationMetadata);// 获取所有候选的配置类List<String> configurations = getCandidateConfigurations(annotationMetadata, attributes);// 去重configurations = removeDuplicates(configurations);// 排除的 configurations(筛查)Set<String> exclusions = getExclusions(annotationMetadata, attributes);checkExcludedClasses(configurations, exclusions);configurations.removeAll(exclusions);configurations = getConfigurationClassFilter().filter(configurations);fireAutoConfigurationImportEvents(configurations, exclusions);// 返回封装了 META-INF/spring.factories 中的自动配置类的Entryreturn new AutoConfigurationEntry(configurations, exclusions);}protected List<String> getCandidateConfigurations(AnnotationMetadata metadata, AnnotationAttributes attributes) {// 获取所有配置类的类全名List<String> configurations = SpringFactoriesLoader.loadFactoryNames(this.getSpringFactoriesLoaderFactoryClass(),	// EnableAutoConfiguration.classthis.getBeanClassLoader());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.");return configurations;}protected Class<?> getSpringFactoriesLoaderFactoryClass() {return EnableAutoConfiguration.class;}}

打个断点debug看一下:

第一次来没筛查的时候有114个

筛查完之后就剩24个了

四、自动装配原理总结

1.第一件事

springBoot约定>配置,很多东西不需要自己去做了,比如扫描,以前需要自己在配置文件里去配,现在不需要了,现在靠启动类的这个@SpringBootApplication注解,这个注解又是一个配置类的注解,又是一个springBoot启动类的注解,这个注解里面包含很多子注解,其中有一个@ComponentScan注解,这个注解替我完成了所有的类交给spring去管理的动作---扫描,所以我要保证其他类在我的启动类的同级以及子包下,这样才能保证扫描到

启动类也是一个配置类,why?

@SpringBootApplication里面还有一个注解:@SpringBootConfiguration,这个注解里面有一个@Configuration注解,他代表这个类是配置类

2.springBoot靠的是自动装配,自动装配说白了就是starter,这一个一个的starter替我完成了自动装配

3.父工程的依赖替我管理着所有的版本

4.所有的东西是怎么被加载到的?怎么被自动装配上的?

通过启动类上的

(@SpringBootApplication)@EnableAutoConfiguration注解,@EnableAutoConfiguration这个注解里面有一个自动导包(@AutoConfigurationPackage)以及

AutoConfigurationImportSelector筛查功能

5.我到底应该装配哪些东西,靠什么?

AutoConfigurationImportSelector里面有一个方法(selectImports()方法),一开始这个方法会筛查出springBoot这个版本所有的自动装配的类

(1)这些东西(springBoot这个版本所有的自动装配的类)在哪?

在spring jar包里的autoconfigure下的META-INF/spring.factories,这个里面整合了所有的autoconfigure

靠读取这些东西拿到

(2)可以看一下spring.factories

1.spring.factories里的内容: 

# Initializers
org.springframework.context.ApplicationContextInitializer=\
org.springframework.boot.autoconfigure.SharedMetadataReaderFactoryContextInitializer,\
org.springframework.boot.autoconfigure.logging.ConditionEvaluationReportLoggingListener# Application Listeners
org.springframework.context.ApplicationListener=\
org.springframework.boot.autoconfigure.BackgroundPreinitializer# Auto Configuration Import Listeners
org.springframework.boot.autoconfigure.AutoConfigurationImportListener=\
org.springframework.boot.autoconfigure.condition.ConditionEvaluationReportAutoConfigurationImportListener# Auto Configuration Import Filters
org.springframework.boot.autoconfigure.AutoConfigurationImportFilter=\
org.springframework.boot.autoconfigure.condition.OnBeanCondition,\
org.springframework.boot.autoconfigure.condition.OnClassCondition,\
org.springframework.boot.autoconfigure.condition.OnWebApplicationCondition# Auto Configure
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
org.springframework.boot.autoconfigure.admin.SpringApplicationAdminJmxAutoConfiguration,\
org.springframework.boot.autoconfigure.aop.AopAutoConfiguration,\
org.springframework.boot.autoconfigure.amqp.RabbitAutoConfiguration,\
org.springframework.boot.autoconfigure.batch.BatchAutoConfiguration,\
org.springframework.boot.autoconfigure.cache.CacheAutoConfiguration,\
org.springframework.boot.autoconfigure.cassandra.CassandraAutoConfiguration,\
org.springframework.boot.autoconfigure.context.ConfigurationPropertiesAutoConfiguration,\
org.springframework.boot.autoconfigure.context.LifecycleAutoConfiguration,\
org.springframework.boot.autoconfigure.context.MessageSourceAutoConfiguration,\
org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration,\
org.springframework.boot.autoconfigure.couchbase.CouchbaseAutoConfiguration,\
org.springframework.boot.autoconfigure.dao.PersistenceExceptionTranslationAutoConfiguration,\
org.springframework.boot.autoconfigure.data.cassandra.CassandraDataAutoConfiguration,\
org.springframework.boot.autoconfigure.data.cassandra.CassandraReactiveDataAutoConfiguration,\
org.springframework.boot.autoconfigure.data.cassandra.CassandraReactiveRepositoriesAutoConfiguration,\
org.springframework.boot.autoconfigure.data.cassandra.CassandraRepositoriesAutoConfiguration,\
org.springframework.boot.autoconfigure.data.couchbase.CouchbaseDataAutoConfiguration,\
org.springframework.boot.autoconfigure.data.couchbase.CouchbaseReactiveDataAutoConfiguration,\
org.springframework.boot.autoconfigure.data.couchbase.CouchbaseReactiveRepositoriesAutoConfiguration,\
org.springframework.boot.autoconfigure.data.couchbase.CouchbaseRepositoriesAutoConfiguration,\
org.springframework.boot.autoconfigure.data.elasticsearch.ElasticsearchDataAutoConfiguration,\
org.springframework.boot.autoconfigure.data.elasticsearch.ElasticsearchRepositoriesAutoConfiguration,\
org.springframework.boot.autoconfigure.data.elasticsearch.ReactiveElasticsearchRepositoriesAutoConfiguration,\
org.springframework.boot.autoconfigure.data.elasticsearch.ReactiveElasticsearchRestClientAutoConfiguration,\
org.springframework.boot.autoconfigure.data.jdbc.JdbcRepositoriesAutoConfiguration,\
org.springframework.boot.autoconfigure.data.jpa.JpaRepositoriesAutoConfiguration,\
org.springframework.boot.autoconfigure.data.ldap.LdapRepositoriesAutoConfiguration,\
org.springframework.boot.autoconfigure.data.mongo.MongoDataAutoConfiguration,\
org.springframework.boot.autoconfigure.data.mongo.MongoReactiveDataAutoConfiguration,\
org.springframework.boot.autoconfigure.data.mongo.MongoReactiveRepositoriesAutoConfiguration,\
org.springframework.boot.autoconfigure.data.mongo.MongoRepositoriesAutoConfiguration,\
org.springframework.boot.autoconfigure.data.neo4j.Neo4jDataAutoConfiguration,\
org.springframework.boot.autoconfigure.data.neo4j.Neo4jRepositoriesAutoConfiguration,\
org.springframework.boot.autoconfigure.data.solr.SolrRepositoriesAutoConfiguration,\
org.springframework.boot.autoconfigure.data.r2dbc.R2dbcDataAutoConfiguration,\
org.springframework.boot.autoconfigure.data.r2dbc.R2dbcRepositoriesAutoConfiguration,\
org.springframework.boot.autoconfigure.data.r2dbc.R2dbcTransactionManagerAutoConfiguration,\
org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration,\
org.springframework.boot.autoconfigure.data.redis.RedisReactiveAutoConfiguration,\
org.springframework.boot.autoconfigure.data.redis.RedisRepositoriesAutoConfiguration,\
org.springframework.boot.autoconfigure.data.rest.RepositoryRestMvcAutoConfiguration,\
org.springframework.boot.autoconfigure.data.web.SpringDataWebAutoConfiguration,\
org.springframework.boot.autoconfigure.elasticsearch.ElasticsearchRestClientAutoConfiguration,\
org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration,\
org.springframework.boot.autoconfigure.freemarker.FreeMarkerAutoConfiguration,\
org.springframework.boot.autoconfigure.groovy.template.GroovyTemplateAutoConfiguration,\
org.springframework.boot.autoconfigure.gson.GsonAutoConfiguration,\
org.springframework.boot.autoconfigure.h2.H2ConsoleAutoConfiguration,\
org.springframework.boot.autoconfigure.hateoas.HypermediaAutoConfiguration,\
org.springframework.boot.autoconfigure.hazelcast.HazelcastAutoConfiguration,\
org.springframework.boot.autoconfigure.hazelcast.HazelcastJpaDependencyAutoConfiguration,\
org.springframework.boot.autoconfigure.http.HttpMessageConvertersAutoConfiguration,\
org.springframework.boot.autoconfigure.http.codec.CodecsAutoConfiguration,\
org.springframework.boot.autoconfigure.influx.InfluxDbAutoConfiguration,\
org.springframework.boot.autoconfigure.info.ProjectInfoAutoConfiguration,\
org.springframework.boot.autoconfigure.integration.IntegrationAutoConfiguration,\
org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration,\
org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration,\
org.springframework.boot.autoconfigure.jdbc.JdbcTemplateAutoConfiguration,\
org.springframework.boot.autoconfigure.jdbc.JndiDataSourceAutoConfiguration,\
org.springframework.boot.autoconfigure.jdbc.XADataSourceAutoConfiguration,\
org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration,\
org.springframework.boot.autoconfigure.jms.JmsAutoConfiguration,\
org.springframework.boot.autoconfigure.jmx.JmxAutoConfiguration,\
org.springframework.boot.autoconfigure.jms.JndiConnectionFactoryAutoConfiguration,\
org.springframework.boot.autoconfigure.jms.activemq.ActiveMQAutoConfiguration,\
org.springframework.boot.autoconfigure.jms.artemis.ArtemisAutoConfiguration,\
org.springframework.boot.autoconfigure.jersey.JerseyAutoConfiguration,\
org.springframework.boot.autoconfigure.jooq.JooqAutoConfiguration,\
org.springframework.boot.autoconfigure.jsonb.JsonbAutoConfiguration,\
org.springframework.boot.autoconfigure.kafka.KafkaAutoConfiguration,\
org.springframework.boot.autoconfigure.availability.ApplicationAvailabilityAutoConfiguration,\
org.springframework.boot.autoconfigure.ldap.embedded.EmbeddedLdapAutoConfiguration,\
org.springframework.boot.autoconfigure.ldap.LdapAutoConfiguration,\
org.springframework.boot.autoconfigure.liquibase.LiquibaseAutoConfiguration,\
org.springframework.boot.autoconfigure.mail.MailSenderAutoConfiguration,\
org.springframework.boot.autoconfigure.mail.MailSenderValidatorAutoConfiguration,\
org.springframework.boot.autoconfigure.mongo.embedded.EmbeddedMongoAutoConfiguration,\
org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration,\
org.springframework.boot.autoconfigure.mongo.MongoReactiveAutoConfiguration,\
org.springframework.boot.autoconfigure.mustache.MustacheAutoConfiguration,\
org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration,\
org.springframework.boot.autoconfigure.quartz.QuartzAutoConfiguration,\
org.springframework.boot.autoconfigure.r2dbc.R2dbcAutoConfiguration,\
org.springframework.boot.autoconfigure.rsocket.RSocketMessagingAutoConfiguration,\
org.springframework.boot.autoconfigure.rsocket.RSocketRequesterAutoConfiguration,\
org.springframework.boot.autoconfigure.rsocket.RSocketServerAutoConfiguration,\
org.springframework.boot.autoconfigure.rsocket.RSocketStrategiesAutoConfiguration,\
org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration,\
org.springframework.boot.autoconfigure.security.servlet.UserDetailsServiceAutoConfiguration,\
org.springframework.boot.autoconfigure.security.servlet.SecurityFilterAutoConfiguration,\
org.springframework.boot.autoconfigure.security.reactive.ReactiveSecurityAutoConfiguration,\
org.springframework.boot.autoconfigure.security.reactive.ReactiveUserDetailsServiceAutoConfiguration,\
org.springframework.boot.autoconfigure.security.rsocket.RSocketSecurityAutoConfiguration,\
org.springframework.boot.autoconfigure.security.saml2.Saml2RelyingPartyAutoConfiguration,\
org.springframework.boot.autoconfigure.sendgrid.SendGridAutoConfiguration,\
org.springframework.boot.autoconfigure.session.SessionAutoConfiguration,\
org.springframework.boot.autoconfigure.security.oauth2.client.servlet.OAuth2ClientAutoConfiguration,\
org.springframework.boot.autoconfigure.security.oauth2.client.reactive.ReactiveOAuth2ClientAutoConfiguration,\
org.springframework.boot.autoconfigure.security.oauth2.resource.servlet.OAuth2ResourceServerAutoConfiguration,\
org.springframework.boot.autoconfigure.security.oauth2.resource.reactive.ReactiveOAuth2ResourceServerAutoConfiguration,\
org.springframework.boot.autoconfigure.solr.SolrAutoConfiguration,\
org.springframework.boot.autoconfigure.task.TaskExecutionAutoConfiguration,\
org.springframework.boot.autoconfigure.task.TaskSchedulingAutoConfiguration,\
org.springframework.boot.autoconfigure.thymeleaf.ThymeleafAutoConfiguration,\
org.springframework.boot.autoconfigure.transaction.TransactionAutoConfiguration,\
org.springframework.boot.autoconfigure.transaction.jta.JtaAutoConfiguration,\
org.springframework.boot.autoconfigure.validation.ValidationAutoConfiguration,\
org.springframework.boot.autoconfigure.web.client.RestTemplateAutoConfiguration,\
org.springframework.boot.autoconfigure.web.embedded.EmbeddedWebServerFactoryCustomizerAutoConfiguration,\
org.springframework.boot.autoconfigure.web.reactive.HttpHandlerAutoConfiguration,\
org.springframework.boot.autoconfigure.web.reactive.ReactiveWebServerFactoryAutoConfiguration,\
org.springframework.boot.autoconfigure.web.reactive.WebFluxAutoConfiguration,\
org.springframework.boot.autoconfigure.web.reactive.error.ErrorWebFluxAutoConfiguration,\
org.springframework.boot.autoconfigure.web.reactive.function.client.ClientHttpConnectorAutoConfiguration,\
org.springframework.boot.autoconfigure.web.reactive.function.client.WebClientAutoConfiguration,\
org.springframework.boot.autoconfigure.web.servlet.DispatcherServletAutoConfiguration,\
org.springframework.boot.autoconfigure.web.servlet.ServletWebServerFactoryAutoConfiguration,\
org.springframework.boot.autoconfigure.web.servlet.error.ErrorMvcAutoConfiguration,\
org.springframework.boot.autoconfigure.web.servlet.HttpEncodingAutoConfiguration,\
org.springframework.boot.autoconfigure.web.servlet.MultipartAutoConfiguration,\
org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration,\
org.springframework.boot.autoconfigure.websocket.reactive.WebSocketReactiveAutoConfiguration,\
org.springframework.boot.autoconfigure.websocket.servlet.WebSocketServletAutoConfiguration,\
org.springframework.boot.autoconfigure.websocket.servlet.WebSocketMessagingAutoConfiguration,\
org.springframework.boot.autoconfigure.webservices.WebServicesAutoConfiguration,\
org.springframework.boot.autoconfigure.webservices.client.WebServiceTemplateAutoConfiguration# Failure analyzers
org.springframework.boot.diagnostics.FailureAnalyzer=\
org.springframework.boot.autoconfigure.data.redis.RedisUrlSyntaxFailureAnalyzer,\
org.springframework.boot.autoconfigure.diagnostics.analyzer.NoSuchBeanDefinitionFailureAnalyzer,\
org.springframework.boot.autoconfigure.flyway.FlywayMigrationScriptMissingFailureAnalyzer,\
org.springframework.boot.autoconfigure.jdbc.DataSourceBeanCreationFailureAnalyzer,\
org.springframework.boot.autoconfigure.jdbc.HikariDriverConfigurationFailureAnalyzer,\
org.springframework.boot.autoconfigure.r2dbc.ConnectionFactoryBeanCreationFailureAnalyzer,\
org.springframework.boot.autoconfigure.session.NonUniqueSessionRepositoryFailureAnalyzer# Template availability providers
org.springframework.boot.autoconfigure.template.TemplateAvailabilityProvider=\
org.springframework.boot.autoconfigure.freemarker.FreeMarkerTemplateAvailabilityProvider,\
org.springframework.boot.autoconfigure.mustache.MustacheTemplateAvailabilityProvider,\
org.springframework.boot.autoconfigure.groovy.template.GroovyTemplateAvailabilityProvider,\
org.springframework.boot.autoconfigure.thymeleaf.ThymeleafTemplateAvailabilityProvider,\
org.springframework.boot.autoconfigure.web.servlet.JspTemplateAvailabilityProvider

2.每一个这样的 xxxAutoConfiguration类都是容器中的一个组件,都加入到容器中;用他们来做自动配置;

3.每一个自动配置类进行自动配置功能;

比如做文件上传:

点进去看:Multipart自动装配
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//package org.springframework.boot.autoconfigure.web.servlet;import javax.servlet.MultipartConfigElement;
import javax.servlet.Servlet;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication.Type;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.multipart.MultipartResolver;
import org.springframework.web.multipart.commons.CommonsMultipartResolver;
import org.springframework.web.multipart.support.StandardServletMultipartResolver;@Configuration(proxyBeanMethods = false
)
@ConditionalOnClass({Servlet.class, StandardServletMultipartResolver.class, MultipartConfigElement.class})
@ConditionalOnProperty(prefix = "spring.servlet.multipart",name = {"enabled"},matchIfMissing = true
)
@ConditionalOnWebApplication(type = Type.SERVLET
)
@EnableConfigurationProperties({MultipartProperties.class})
public class MultipartAutoConfiguration {private final MultipartProperties multipartProperties;public MultipartAutoConfiguration(MultipartProperties multipartProperties) {this.multipartProperties = multipartProperties;}@Bean@ConditionalOnMissingBean({MultipartConfigElement.class, CommonsMultipartResolver.class})public MultipartConfigElement multipartConfigElement() {return this.multipartProperties.createMultipartConfig();}@Bean(name = {"multipartResolver"})@ConditionalOnMissingBean({MultipartResolver.class})public StandardServletMultipartResolver multipartResolver() {StandardServletMultipartResolver multipartResolver = new StandardServletMultipartResolver();multipartResolver.setResolveLazily(this.multipartProperties.isResolveLazily());return multipartResolver;}
}
自动装配的什么

Multipart得有上传的大小,点进去MultipartProperties

 

//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//package org.springframework.boot.autoconfigure.web.servlet;import javax.servlet.MultipartConfigElement;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.PropertyMapper;
import org.springframework.boot.web.servlet.MultipartConfigFactory;
import org.springframework.util.unit.DataSize;@ConfigurationProperties(prefix = "spring.servlet.multipart",ignoreUnknownFields = false
)
public class MultipartProperties {private boolean enabled = true;private String location;private DataSize maxFileSize = DataSize.ofMegabytes(1L);private DataSize maxRequestSize = DataSize.ofMegabytes(10L);private DataSize fileSizeThreshold = DataSize.ofBytes(0L);private boolean resolveLazily = false;public MultipartProperties() {}public boolean getEnabled() {return this.enabled;}public void setEnabled(boolean enabled) {this.enabled = enabled;}public String getLocation() {return this.location;}public void setLocation(String location) {this.location = location;}public DataSize getMaxFileSize() {return this.maxFileSize;}public void setMaxFileSize(DataSize maxFileSize) {this.maxFileSize = maxFileSize;}public DataSize getMaxRequestSize() {return this.maxRequestSize;}public void setMaxRequestSize(DataSize maxRequestSize) {this.maxRequestSize = maxRequestSize;}public DataSize getFileSizeThreshold() {return this.fileSizeThreshold;}public void setFileSizeThreshold(DataSize fileSizeThreshold) {this.fileSizeThreshold = fileSizeThreshold;}public boolean isResolveLazily() {return this.resolveLazily;}public void setResolveLazily(boolean resolveLazily) {this.resolveLazily = resolveLazily;}public MultipartConfigElement createMultipartConfig() {MultipartConfigFactory factory = new MultipartConfigFactory();PropertyMapper map = PropertyMapper.get().alwaysApplyingWhenNonNull();map.from(this.fileSizeThreshold).to(factory::setFileSizeThreshold);map.from(this.location).whenHasText().to(factory::setLocation);map.from(this.maxRequestSize).to(factory::setMaxRequestSize);map.from(this.maxFileSize).to(factory::setMaxFileSize);return factory.createMultipartConfig();}
}
 这里是有默认值的,可以改,在配置文件里改:

 

 application.yml

自动装配就是在这做的

6.但是这些东西有很多个,我要根据我现在的pom文件的配置以及默认配置去筛查,会先筛查一部分,等什么时候再有了再导再去做自动装配

筛查

@SpringBootApplication--->@EnableAutoConfiguration(靠它去自动导入,但是他会自动装配很多所有的Configuration)-->

@Import(EnableAutoConfigurationImportSelector.class)(我不要那么多Configuration,所以靠他去筛查,筛查出来我目前需要到的Configuration,形成一个Configurations,之后我用到别的了再重新装配)(这里面有一个方法selectImports,这个方法是去筛查的)

(1)spring.factories这个文件里面每一个配置里面都有一些默认配置,比如HttpEncodingAutoConfiguration可以设置编码,怎么设置?

他里面有一个ServerProperties,(ServerProperties)他里面有个前缀:

也有一些默认值

(2)不想使用它的默认值,怎么改?

在application.yml配置文件去改变它

7.在自动装配的时候,启动类一启动会读取配置文件,配置文件就会被加载,到自动筛查的时候:

他看你的配置文件里有没有信息,有我就改变他,没有就采用默认值

五.SpringBoot的热部署

spring为开发者提供了一个名为spring-boot-devtools的模块来使Spring Boot应用支持热部署,提高开发者的开发效率,无需手动重启Spring Boot应用。

引入依赖

<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> <optional>true</optional> 
</dependency>

就是加个依赖然后ctrl+f9就可以了,以前的时候改了代码得重启,现在不用了,加个依赖,ctrl+f9就可以了

相关文章:

SpringBoot的注解@SpringBootApplication及自动装配

目录 一、pom文件 二、SpringBootApplication注解 1.SpringBootApplication 2.Configuration 3.这个启动类也可以被看成是一个配置类 三、SpringBootApplication注解2 1.SpringBootConfiguration 2.Configuration 3.EnableAutoConfiguration&#xff01;&#xff01;&…...

STM32学习之EXTI外部中断(以对外式红外传感器 / 旋转编码器为例)

中断:在主程序运行过程中&#xff0c;出现了特定的中断触发条件(中断源)&#xff0c;使得CPU暂停当前正在运行的程序&#xff0c;转而去处理中断程序处理完成后又返回原来被暂停的位置继续运行 中断优先级:当有多个中断源同时申请中断时&#xff0c;CPU会根据中断源的轻重缓急…...

数字赋能:制造企业如何靠“数字能力”实现可持续“超车”?

如今&#xff0c;制造业数字化转型可是个热门话题&#xff0c;全球都在积极推进。我国更是出台了一系列给力的政策来助力制造业数字化转型&#xff0c;像《中国制造 2025》就明确提出要加快制造业数字化、网络化、智能化发展&#xff0c;各省市也纷纷响应&#xff0c;从资金、税…...

.NET在中国的就业前景:开源与跨平台带来的新机遇

随着技术的不断发展和市场需求的变化&#xff0c;.NET在中国的就业前景正变得愈加广阔。尤其是在开源和跨平台的推动下&#xff0c;越来越多的中国中小型企业选择了.NET技术作为其开发平台&#xff0c;进一步提升了.NET技术人才的市场需求。尽管在中国市场&#xff0c;.NET的市…...

【基础篇】一、MySQL数据库基础知识

文章目录 Ⅰ. 什么是数据库1、普通文件的缺点2、数据库的概念3、主流数据库4、MySQL Ⅱ. MySQL中客户端、服务端、数据库的关系Ⅲ. 见一见数据库1、数据库文件存放的位置2、创建数据库3、使用数据库4、创建数据库表结构5、表中插入数据6、查询表中数据7、数据的存储逻辑 &#…...

预训练深度双向 Transformers 做语言理解

大家读完觉得有意义记得关注和点赞&#xff01;&#xff01;&#xff01; 与 GPT 一样&#xff0c;BERT 也基于 transformer 架构&#xff0c; 从诞生时间来说&#xff0c;它位于 GPT-1 和 GPT-2 之间&#xff0c;是有代表性的现代 transformer 之一&#xff0c; 现在仍然在很多…...

理解js闭包,原型,原型链

闭包 一个函数嵌套了另一个函数&#xff0c;内部函数引用了外部函数的变量&#xff0c;这样&#xff0c;当外部函数在执行环境中执行完毕后&#xff0c;因为某个变量被引用就无法被GC回收&#xff0c;导致这个变量会一直保持在内存中不能被释放。因此可以用来封装一个私有变量…...

linux tar 文件解压压缩

文件压缩和解压 tar -c: 建立压缩档案 -x&#xff1a;解压 -t&#xff1a;查看内容 -r&#xff1a;向压缩归档文件末尾追加文件 -u&#xff1a;更新原压缩包中的文件 -z&#xff1a;有gzip属性的 -j&#xff1a;有bz2属性的 -v&#xff1a;显示所有过程 -O&#xff1a;…...

【SQL server】教材数据库(5)

使用教材数据库&#xff08;1&#xff09;中的数据表完成以下题目&#xff1a; 1 根据上面基本表的信息定义视图显示每个学生姓名、应缴书费 2 观察基本表数据变化时&#xff0c;视图中数据的变化。 3利用视图&#xff0c;查询交费最高的学生。 1、create view 学生应缴费视…...

Oracle 11G还有新BUG?ORACLE 表空间迷案!

前段时间遇到一个奇葩的问题&#xff0c;在开了SR和oracle support追踪两周以后才算是有了不算完美的结果&#xff0c;在这里整理出来给大家分享。 1.问题描述 12/13我司某基地MES全厂停线&#xff0c;系统卡死不可用&#xff0c;通知到我排查&#xff0c;查看alert log看到是…...

java实现预览服务器文件,不进行下载,并增加水印效果

通过文件路径获取文件&#xff0c;对不同类型的文件进行不同处理&#xff0c;将Word文件转成pdf文件预览&#xff0c;并早呢更加水印&#xff0c;暂不支持Excel文件&#xff0c;如果浏览器不支持PDF文件预览需要下载插件。文中currentUser.getUserid()&#xff0c;即为增加的水…...

SAP月结、年结前重点检查事项(后勤与财务模块)

文章目录 一、PP生产模块相关的事务检查二、SD销售模块相关的事务检查:三、MM物料管理模块相关的事务检查四、FICO财务模块相关的事务检查五、年结前若干注意事项【SAP系统PP模块研究】 #SAP #生产订单 #月结 #年结 一、PP生产模块相关的事务检查 1、月末盘点后,生产用料的…...

MYSQL 高阶语句

目录 1、排列查询 2、区间判断 3、对结果进行分组查询 4、limit和distinct 5、设置别名 通配符 6、子查询 7、exists语句&#xff0c;判断子查询的结果是否为空 8、视图表 9、连接查询 1. 内连接 2. 左连接 3. 右连接 create table info ( id int primary key, name…...

VS Code中怎样查看某分支的提交历史记录

VsCode中无法直接查看某分支的提交记录&#xff0c;需借助插件才行&#xff0c;常见的插件如果git history只能查看某页面的改动记录&#xff0c;无法查看某分支的整体提交记录&#xff0c;我们可以安装GIT Graph插件来解决这个问题 1.在 VSCode的插件库中搜索 GIT Graph安装&a…...

知识库搭建实战一、(基于 Qianwen 大模型的知识库搭建)

基于 Qianwen 大模型的知识库开发规划 基础环境搭建可以参考文章:基础环境搭建 在构建智能应用时,知识库是一个重要的基础模块。以下将基于 Qianwen 大模型,详细介绍构建一个标准知识库的设计思路及其实现步骤。 知识库的核心功能模块 知识库开发的核心功能模块主要包括…...

ctr方法下载的镜像能用docker save进行保存吗?

ctr 和 docker 是两个不同的容器运行时工具,它们使用的镜像存储格式是兼容的(都是 OCI 标准镜像),但它们的镜像管理方式和存储路径不同。因此,直接使用 docker save 保存 ctr 拉取的镜像可能会遇到问题。 关键点 ctr 和 docker 的镜像存储位置不同: ctr(containerd)的镜…...

win32汇编环境下,窗口程序中生成listview列表控件及显示

;运行效果 ;抄下面源码在radasm里面&#xff0c;可以直接编译运行。重要部分加了备注。 ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>&…...

运维之网络安全抓包—— WireShark 和 tcpdump

为什么要抓包&#xff1f;何为抓包&#xff1f; 抓包&#xff08;packet capture&#xff09;就是将网络传输发送与接收的数据包进行截获、重发、编辑、转存等操作&#xff0c;也用来检查网络安全。抓包也经常被用来进行数据截取等。为什么要抓包&#xff1f;因为在处理 IP网络…...

【复刻】数字化转型是否赋能企业新质生产力发展?(2015-2023年)

参照赵国庆&#xff08;2024&#xff09;的做法&#xff0c;对来自产业经济评论《企业数字化转型是否赋能企业新质生产力发展——基于中国上市企业的微观证据》一文中的基准回归部分进行复刻基于2015-2023年中国A股上市公司数据&#xff0c;实证分析企业数字化转型对新质生产力…...

【数据仓库】spark大数据处理框架

文章目录 概述架构spark 架构角色下载安装启动pyspark启动spark-sehll启动spark-sqlspark-submit经验 概述 Spark是一个性能优异的集群计算框架&#xff0c;广泛应用于大数据领域。类似Hadoop&#xff0c;但对Hadoop做了优化&#xff0c;计算任务的中间结果可以存储在内存中&a…...

2 秒杀系统架构

第一步 思考面临的问题和业务场景 秒杀系统面临的问题: 短时间内并发非常高&#xff0c;如果按照秒杀的并发做相应的承载会造成大量资源的浪费。第二解决超卖的问题。 第二步 思考目前的处境和解决方案 因为秒杀系统属于短时间内的高并发问题&#xff0c;我们不可能使用那么…...

UNI-APP_i18n国际化引入

官方文档&#xff1a;https://uniapp.dcloud.net.cn/tutorial/i18n.html vue2中使用 1. 新建文件 locale/index.js import en from ./en.json import zhHans from ./zh-Hans.json import zhHant from ./zh-Hant.json const messages {en,zh-Hans: zhHans,zh-Hant: zhHant }…...

【详解】AndroidWebView的加载超时处理

Android WebView的加载超时处理 在Android开发中&#xff0c;WebView是一个常用的组件&#xff0c;用于在应用中嵌入网页。然而&#xff0c;当网络状况不佳或页面加载过慢时&#xff0c;用户可能会遇到加载超时的问题。为了提升用户体验&#xff0c;我们需要对WebView的加载超时…...

RedisDesktopManager新版本不再支持SSH连接远程redis后

背景 RedisDesktopManager(又名RDM)是一个用于Windows、Linux和MacOS的快速开源Redis数据库管理应用程序。这几天从新下载RedisDesktopManager最新版本&#xff0c;结果发现新版本开始不支持SSH连接远程redis了。 解决方案 第一种 根据网上有效的信息&#xff0c;可以回退版…...

开源 SOAP over UDP

简介 看到有人想要实现两个 EXE 之间的互动。这可以采用 RPC 的方式嘛。 Delphi 现成的 RPC 框架&#xff0c;比如 WebService&#xff0c;比如 DataSnap&#xff1b; 当然&#xff0c;github 上面还有第三方开源的 XMLRPC 等等。 为啥要搞一个 UDP Delphi 的 WebService …...

Levenshtein 距离的原理与应用

引言 在文本处理和自然语言处理&#xff08;NLP&#xff09;中&#xff0c;衡量两个字符串相似度是一项重要任务。Levenshtein 距离&#xff08;也称编辑距离&#xff09;是一种常见的算法&#xff0c;用于计算将一个字符串转换为另一个字符串所需的最少编辑操作次数。这些操作…...

解决json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

前言 作者在读取json文件的时候出现上述报错&#xff0c;起初以为是自己json文件有问题&#xff0c;但借助在线工具查看后发现没问题&#xff0c;就卡住了&#xff0c;在debug的过程中发现了json文件读取的一个小坑&#xff0c;在此分享一下 解决过程 原代码 with open(anno…...

hive中的四种排序类型

1、Order by 全局排序 ASC&#xff08;ascend&#xff09;: 升序&#xff08;默认&#xff09; DESC&#xff08;descend&#xff09;: 降序 注意 &#xff1a;只有一个 Reducer,即使我们在设置set reducer的数量为多个,但是在执行了order by语句之后,当前此次的运算还是只有…...

Spring-AI讲解

Spring-AI langchain(python) langchain4j 官网&#xff1a; https://spring.io/projects/spring-ai#learn 整合chatgpt 前置准备 open-ai-key: https://api.xty.app/register?affPuZD https://xiaoai.plus/ https://eylink.cn/ 或者淘宝搜&#xff1a; open ai key魔法…...

【brew安装失败】DNS 查询 raw.githubusercontent.com 返回的是 0.0.0.0

从你提供的 nslookup 输出看&#xff0c;DNS 查询 raw.githubusercontent.com 返回的是 0.0.0.0&#xff0c;这通常意味着无法解析该域名或该域名被某些 DNS 屏蔽了。这种情况通常有几个可能的原因&#xff1a; 可能的原因和解决方法 本地 DNS 问题&#xff1a; 有可能是你的本…...