1.@SpringBootApplication:说明这个类是SpringBoot的主配置类,运行其main方法启动Spring Boot应用。
2.@SpringBootConfiguration:Spring Boot的配置类。
3.@Configuration:配置类上标注这个注解。配置类也是容器中的一个组件;@Component
4.@EnableAutoConfiguration:开启自动配置功能,自动配置功能生效。
5.@Import(AutoConfigurationPackages.Registrar.class):给容器中导入组件。
–AutoConfigurationPackages.Registrar.class;将主配置类(@SpringBootApplication标注的类)的所在包及下面所有子包里面的所有组件扫描到Spring容器
@Import(EnableAutoConfigurationImportSelector.class);EnableAutoConfigurationImportSelector:导入哪些组件的选择器;
将所有需要导入的组件以全类名的方式返回;这些组件就会被添加到容器中会给容器中导入非常多的自动配置类(xxxAutoConfiguration),就是给容器中导入这个场景需要的所有组件。
6.@ConfigrationProperties(prefix=”“):配置文件与pojo中类的属性进行一一映射。前提,pojo类是容器中的组件。即pojo类用@Conmponent.
7.@PropertySource:加载指定的配置文件。 –@PropertySource(value = {“classpath:person.properties”})
8.@ImportResource:导入Spring 的配置文件,让配置文件里面的内容生效。 –@ImportResource(location = {“classpath:beans.xml”})
9.@Bean:给容器中添加组件。
例:传统配置been
<bean id="helloService" class="com.sitech.springboot.service.HelloService"></bean>
Spring Boot推荐使用全注解:
@Configuration
public class HelloService{
@Bean
public HelloService helloService(){
return new HelloService();
}
}
10.@ConditionalOnXXX:Spring底层注解@Conditional,根据不同的条件,如果满足指定的条件,整个配置类里面的配置就会生效。
例:10.1. @ConditionalOnWebApplication:判断当前应用是否是web应用,如果是,当前配置类生效。
10.2. @ConditionalOnClass(CharacterEncodingFilter.class):判断当前项目有没有这个类。CharacterEncoingFilter:SpringMvc进行乱码解决的过滤器。
10.3. @ConditionalOnProperty(prefix = “spring.http.encoding”,value = “enable”,matchIfMissing = true)
判断配置文件是否存在某个配置 spring.http.encoding.enabled;如果不存在,判断也是成立的
即使配置文件中不配置spring.http.encoding.enabled = true,也是默认生效的。