原创转载请注明出处:https://www.cnblogs.com/agilestyle/p/14917975.html

 

原理

@SpringBootApplication 是一个复合注解,包括

  • @SpringBootConfiguration
  • @EnableAutoConfiguration
  • @ComponentScan

这3个注解的作用就是把项目工程中定义的Bean 注入到 Spring IoC 容器中。

@SpringBootApplication 之 @EnableAutoConfiguration

 

@EnableAutoConfiguration 源码

@SpringBootApplication 之 @EnableAutoConfiguration

Note: 

@Import 作用就是将指定的类实例注入到Spring IoC 容器中

 

@Import 分析

Project Directory

@SpringBootApplication 之 @EnableAutoConfiguration

 

Maven Dependency

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.3.12.RELEASE</version>
        <relativePath/>
    </parent>

    <groupId>org.fool</groupId>
    <artifactId>hellospring</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <maven.compiler.source>8</maven.compiler.source>
        <maven.compiler.target>8</maven.compiler.target>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>
View Code

相关文章:

  • 2022-12-23
  • 2021-06-04
  • 2021-07-18
  • 2021-11-29
  • 2022-12-23
  • 2022-01-10
  • 2021-07-01
  • 2021-07-11
猜你喜欢
  • 2021-11-26
  • 2021-06-16
  • 2021-06-30
  • 2021-06-19
  • 2022-03-10
  • 2022-01-22
相关资源
相似解决方案