Giter Site home page Giter Site logo

Comments (7)

zyllt avatar zyllt commented on August 11, 2024

SpringBootApplication注解是定义在spring-boot-autoconfigure模块中,通常被用作启动一个spring boot项目main方法所在类的注解。例如:
@SpringBootApplication public class SimpleMainTests { public static void main(String[] args) { SpringApplication.run(SimpleMainTests.class, new String[]{}); }}

from project.

zyllt avatar zyllt commented on August 11, 2024

该注解的官方说明

Indicates a configuration class that declares one or more @bean methods and also triggers auto-configuration and component scanning. This is a convenience annotation that is equivalent to declaring @configuration, @EnableAutoConfiguration and @componentscan.

指示一个Configuration类,该类声明一个或多个@bean方法,并触发EnableAutoConfiguration自动配置和ComponentScan组件扫描。其实就是一个复合注解,把@configuration、@EnableAutoConfiguration和@componentscan放在了一起。

from project.

zyllt avatar zyllt commented on August 11, 2024

看源码
@SpringBootConfiguration
@EnableAutoConfiguration

@componentscan(excludeFilters = {
@filter(type = FilterType.CUSTOM, classes = TypeExcludeFilter.class),
@filter(type = FilterType.CUSTOM, classes = AutoConfigurationExcludeFilter.class) })

from project.

zyllt avatar zyllt commented on August 11, 2024

@SpringBootConfiguration是@configuration的一种继承,在spring boot项目使用

from project.

zyllt avatar zyllt commented on August 11, 2024

@componentscan还是熟悉的味道,添加了2个custom的excludeFilter。其中TypeExcludeFilter主要是用在spring boot test中,不用关注。AutoConfigurationExcludeFilter是让自动配置的类不需要被ComponentScan扫描,它们有自己的注册方式。

from project.

zyllt avatar zyllt commented on August 11, 2024

@EnableAutoConfiguration 顾名思义就是用来启用spring boot的自动配置功能。

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

from project.

zyllt avatar zyllt commented on August 11, 2024

@EnableAutoConfiguration 其实就是引入了一个AutoConfigurationImportSelector类,从名称其实就可以看出它实现了ImportSelector,这接口的作用其实就是用来选择那些@configuration类被引入。but AutoConfigurationImportSelector 其实是实现了DeferredImportSelector接口,DeferredImportSelector是ImportSelector的一个变体,它是在所有的@configuration bean被处理完之后才运行的,主要是用来处理Conditional

from project.

Related Issues (19)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.