@EnableAutoConfiguration
Start auto mount: After using this annotation, all the starters of the imported jar will be automatically injected. The design of this class is to work for starter.
@RestController
This annotation is dedicated to the writing of restful interfaces, with @controller and @responsebody annotations integrated.
@ResponseBody This annotation automatically uses the default Jackson to serialize the return object into JSON format.
@RequestMapping, @GetMapping, @PostMapping
These annotations are primarily about configuring routing information.
@Import, @ImportResource, @Configuration, @PropertySources
@Configuration: Identifies the current class as a Java configuration class
@Import: For manual injection of the Java Config class.
@ImportResource: Used to inject XML configuration classes.
@PropertySources: A configuration file that is used to inject properties.
@Value, @ConfigurationProperties
@Value This annotation automatically injects the property value configured within the properties file via the Set key. Like what
@Value ("${test.name}") automatically introduces the value of the Test.name configured within the properties file.
The role of @ConfigurationProperties is similar to that of @value, but it is a little cumbersome to use and will not be explained.
To view automatically loaded classes:
If you need to the find out what auto-configuration are currently being applied, and why, start your application with The–debu G Switch. This would enable debug logs for a selection of core loggers and log an auto-configuration the console.
@SpringBootApplication
@SpringBootApplication annotations are equivalent to using @Configuration, @EnableAutoConfiguration, and @ComponentScan with default properties.
Here's one thing to note: If we need to disable some special auto-loaded classes. You can use the Exclude property of @enableautoconfiguration to remove automatically loaded classes. Of course, it is also possible to add this attribute to the @springbootapplication annotation.
@ComponentScan
Component scanning, if loading application on this class, does not require parameters, the auto-sweep polygon application is located under the path and underneath the package. Otherwise, you need to add a scan package path.
Automatic scanning: @Repository, @Service, @Controller, @Component components.
@Repository, @Service, @Controller, @Component
Component annotations: Use @component in annotaion configuration annotations to denote a generic comment that describes a class as a spring container-managed class. That is, the class has been pulled into the management of spring. And @controller, @Service, @Repository is the refinement of @component, these three annotations with more semantics than @component, they correspond to the control layer, service layer, the class of the persistence layer respectively.
@Repository Annotations: For labeling data Access Components, DAO components
@Service Annotations: For labeling business layer components
@Controller Annotations: For labeling control-layer components, such as action in struts
@Component Note: Refer to the component, we can use this annotation to annotate when the component is not well categorized.
@Profile
This annotation is mainly added to the @component or @Configuration. Identifies the current profile environment. For different environments, you can choose whether to load these configurations.
Then select the environment in the application.properties, separated by commas.
Spring.profiles.active=xxxx
@ServletComponentScan
@ServletComponentScan Note plus a post-interceptor failure; After removing the filter and the listener fails
@EnableCaching
Open cache cache support;
@PathVariable:
The PATH variable.
@Conditional and its meta-annotations
@Conditional: The creation of a bean,springboot to meet certain conditions is to use this feature for automatic configuration;
@ConditionalOnProperty: Whether the specified property has a specified value;
@ConditionalOnClass: Under conditions where the class path has the specified class
@Autowired and @resource
@Autowired: Load by Type by default
@Resource: The default is loaded by the Bean's name
However, both of the above can be injected into the bean's name via the @qualifier annotation setting
Spring Boot common annotations