欢迎访问 生活随笔!

生活随笔

当前位置: 首页 >

batch normalization的原理和作用_springboot自动配置原理

发布时间:2025/3/20 35 豆豆
生活随笔 收集整理的这篇文章主要介绍了 batch normalization的原理和作用_springboot自动配置原理 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

配置文件能配置的属性参照https://docs.spring.io/spring-boot/docs/1.5.9.RELEASE/reference/htmlsingle/#common-application-properties

1、自动配置原理:

1)SpringBoot启动的时候加载主配置类,开启了自动配置功能@EnableAutoConfiguration

2)@EnableAutoConfiguration 作用:

利用EnableAutoConfigurationImportSelector给容器中导入一些组件

可以查看selectImports()方法的内容;

List configurations = getCandidateConfigurations(annotationMetadata, attributes);

获取候选的配置

SpringFactoriesLoader

将 类路径下 META-INF/spring.factories 里面配置的所有EnableAutoConfiguration的值加入到了容中;

#

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

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

4)、以HttpEncodingAutoConfiguration(Http编码自动配置)为例解释自动配置原理;

@Configuration

根据当前不同的条件判断,决定这个配置类是否生效?

一但这个配置类生效;这个配置类就会给容器中添加各种组件;这些组件的属性是从对应的properties类中获取的,这些类里面的每一个属性又是和配置文件绑定的;

5)、所有在配置文件中能配置的属性都是在xxxxProperties类中封装者‘;配置文件能配置什么就可以参照某个功能对应的这个属性类

@ConfigurationProperties(prefix = "spring.http.encoding") //从配置文件中获取指定的值和bean的属

性进行绑定

public

1)SpringBoot启动会加载大量的自动配置类

2)我们看我们需要的功能有没有SpringBoot默认写好的自动配置类;

3)我们再来看这个自动配置类中到底配置了哪些组件;(只要我们要用的组件有,我们就不需要再来配置了)

4)给容器中自动配置类添加组件的时候,会从properties类中获取某些属性。我们就可以在配置文件中指定这些属性的值;

xxxxAutoConfigurartion:自动配置类;

给容器中添加组xxxxProperties:封装配置文件中相关属性

2、细节

2.1@Conditional派生注解(Spring注解版原生的@Conditional作用)

作用:必须是@Conditional指定的条件成立,才给容器中添加组件,配置配里面的所有内容才生效

自动配置类必须在一定的条件下才能生效;

我们怎么知道哪些自动配置类生效; 我们可以通过启用 debug=true属性;来让控制台打印自动配置报告,这样我们就可以很方便的知道哪些自动配置 类生效;

========================= AUTO‐CONFIGURATION REPORT ========================= Positive matches:(自动配置类启用的) ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ DispatcherServletAutoConfiguration matched:‐ @ConditionalOnClass found required class 'org.springframework.web.servlet.DispatcherServlet'; @ConditionalOnMissingClass did not find unwanted class (OnClassCondition) ‐ @ConditionalOnWebApplication (required) found StandardServletEnvironment (OnWebApplicationCondition) Negative matches:(没有启动,没有匹配成功的自动配置类) ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ ActiveMQAutoConfiguration: Did not match: ‐ @ConditionalOnClass did not find required classes 'javax.jms.ConnectionFactory', 'org.apache.activemq.ActiveMQConnectionFactory' (OnClassCondition) AopAutoConfiguration: Did not match: ‐ @ConditionalOnClass did not find required classes 'org.aspectj.lang.annotation.Aspect', 'org.aspectj.lang.reflect.Advice' (OnClassCondition)

总结

以上是生活随笔为你收集整理的batch normalization的原理和作用_springboot自动配置原理的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。