SpringBoot Hello World主程序分析(学习笔记5)

这篇博客详细分析了SpringBoot的Hello World主程序,重点讲解了@SpringBootApplication的作用。该注解结合了@SpringBootConfiguration、@EnableAutoConfiguration和@ComponentScan,用于启动SpringBoot应用并进行配置。@EnableAutoConfiguration开启自动配置功能,扫描主配置类及其子包下的组件。自动配置的核心在于spring-boot-autoconfigure-*.RELEASE.jar,提供J2EE的整合和配置。
摘要由CSDN通过智能技术生成

1、@SpringBootApplication 来标注一个主程序类,说明这是一个 Spring Boot 应用。@SpringBootApplication 标注哪个类上, Spring Boot 就运行这个类的 main 方法,来启动SpringBoot应用。一个@SpringbootApplication相当于@Configuration,@EnableAutoConfiguration和 @ComponentScan等并具有他们的默认属性值, 它是一个组合注解:

@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}
)}
)


@SpringBootConfiguration Spring Boot 的配置类;这个注解标注哪个类上,就表示这个类是 Spring Boot 的配置类,点击 @SpringBootConfiguration 注解:


在这里我们可以看到 @Configuration 注解,@Configuration 注解是Spring定义的注解。相当于传统的xml配置文件,如果有些第三方库需要用到xml文件,建议仍然通过@Configuration类作为项目的配置主类——可以使用@ImportResource注解加载xml配置文件。

2、@EnableAutoConfiguration 开启自动配置功能;它是一个组合注解:

@AutoConfigurationPackage:自动配置包;将主配置类(@SpringBootApplication标识的类)的所在包及下面所有子包里面的所有组件扫描到Spring容器。

@Import({AutoConfigurationImportSelector.class}) @Import是Spring底层注解,给容器中导入组件。


@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Inherited
@AutoConfigurationPackage
@Import({AutoConfigurationImportSelector.class})
public @interface EnableAutoConfiguration {
    String ENABLED_OVERRIDE_PROPERTY = "spring.boot.enableautoconfiguration";

    Class<?>[] exclude() default {};

    String[] excludeName() default {};
}



J2EE的整体整合解决方案和自动配置都在spring-boot-autoconfigure-*.RELEASE.jar.



感谢--尚硅谷


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值