Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

CoderViking/MySpringBoot

Open more actions menu

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

93 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MySpringBoot

That is a project for learning the springBoot

The demo of Learning springBoot

SpringMVC自动配置

配置文件能配置的属性参照

springBoot 自动注入原理

  • 1.在SpringBootApplication.java类中添加一个@EnableAutoConfiguration注解
  • 2.该注解会在spring-boot-autoconfigure包下的WEB-INF目录下去加载spring.factories文件中的所有xxxAutoConfiguration组件
  • 3.在每个组件中都有一个@Configuration注解,表示这个类是一个配置类;@ConditionalOnXXX这个注解是判断这个配置类加载的条件,条件成立才生效,否则不生效;
       若自动配置组件类中包含@EnableConfigurationProperties这个注解或者有private final MongoProperties properties;这样的属性,
       那么表示这个自动配置组件是可以通过读取配置文件来获取用户自定义的配置属性的,具体的配置字段名都在xxxProperties类中
  • 4.一但这个配置类生效;这个配置类就会给容器中添加各种组件;这些组件的属性是从对应的properties类中获取的,这些类里面的每一个属性又是和配置文件绑定的;
  • 5.所有在配置文件中能配置的属性都是在xxxProperties类中封装着;配置文件能配置什么就可以参照某个功能对应的这个属性类

总结

  • 1.SpringBoot启动会加载大量的自动配置类
  • 2.在需要时我们看一下需要的功能有没有SpringBoot默认写好的自动配置类;
  • 3.然后再看一下这个自动配置类中到底配置了哪些组件;(只要我们要用的组件有,我们就不需要再来配置了)
  • 4.给容器中自动配置类添加组件的时候,会从properties类中获取某些属性。我们就可以在配置文件中指定这些属性的值;
  • 5.xxxAutoConfiguration: 自动配置类 给容器中添加组件
  • 6.xxxProperties: 封装配置文件中相关属性

About

That is a project for learning the springBoot

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

Morty Proxy This is a proxified and sanitized view of the page, visit original site.