Spring Boot core annotation

The biggest feature of Spring Boot is that no XML configuration file is required. It can automatically scan the package path to load and inject objects, and can be automatically configured according to the JAR package in the classpath.

So the three core notes of Spring Boot are:

1. @ the Configuration

org.springframework.context.annotation.Configuration
This is an annotation added by Spring 3.0 to replace the ApplicationContext.xml configuration file, and everything that can be done in this configuration file can be registered with the class in which the annotation is made.

The following related notes are also very important!

@Bean

Instead of

configuration.

@ImportResource

This annotation can be used to introduce additional XML Configuration files that cannot be configured via class registration. Some older Configuration files do not work well with @Configuration.

@Import

Config file class used to introduce one or more additional @Configuration modifications.

@SpringBootConfiguration

This annotation is a variation of the @Configuration annotation, which is used to modify the Spring Boot Configuration, or to facilitate subsequent Spring Boot extensions. The source code is as follows.

@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Configuration
public @interface SpringBootConfiguration {

}

Copy the code

2, @ ComponentScan

org.springframework.context.annotation.ComponentScan
This is an annotation added in Spring 3.1 to replace the Component-scan configuration in the configuration file and enable component scanning, which automatically scans the @Component annotation in the package path to register bean instances into the context.

In addition, @ComponentScans is a repeatable annotation, that is, multiple annotations can be configured to register different subpackages.



3, @ EnableAutoConfiguration

org.springframework.boot.autoconfigure.EnableAutoConfiguration
This is an annotation added since the birth of Spring Boot to provide automatic configuration. The above two annotations are in the spring-Context package and do not belong to Spring Boot. So the de-XML configuration after Spring 3.0 has been foreshadowed for Spring Boot!


4. The last