springboot Common annotations in are :


This annotation is Spring Boot Core notes , Used in Spring Boot On the main class of , Logo this is a Spring Boot application , Used to open Spring
Capabilities of . Actually, this annotation is @Configuration,@EnableAutoConfiguration,@ComponentScan Combination of three annotations . Because these annotations are generally used together , therefore Spring
Boot Provides a unified annotation @SpringBootApplication.


allow Spring Boot Auto configure annotations , After opening this annotation ,Spring Boot It can be configured according to the package or class under the current classpath Spring Bean.

as : There are Mybatis this JAR package ,MybatisAutoConfiguration Annotations can be configured according to relevant parameters Mybatis Each of
Spring Bean.

@EnableAutoConfiguration The key to implementation is the introduction of AutoConfigurationImportSelector, Its core logic is selectImports method , The logic is roughly as follows :

 ●  From profile META-INF/spring.factories Load all possible autoconfiguration classes ;

 ●  duplicate removal , And will exclude and excludeName Class exclusion carried by property ;

 ●  filter , Conditions will be met (@Conditional) Auto configuration class return for ;


Used to define configuration classes , Indicates that this class is Bean
Configured information sources , Equivalent to traditional xml configuration file , Generally added to the main class . If some third-party libraries need to be used xml file , Recommendation still adopted @Configuration Class as the main configuration class of the project —— have access to @ImportResource Annotation loading xml configuration file .


Component scan . Give Way spring Boot Scan to Configuration Class and add it to the program context .

@ComponentScan The annotation will be marked by default @Controller,@Service,@Repository,@Component Annotated classes to spring In container .


For dimensioning data access components , Namely DAO assembly .

use @Repository Annotations ensure that DAO perhaps repositories Provide exception translation , This annotation modifies DAO perhaps repositories Class will be ComponetScan Discover and configure , And there is no need to provide XML Configuration item .


Generally used to decorate service Components of layer


For dimensioning control layer components ( as struts Medium action), Indicates that this is a controller bean, And the return value of the function is directly
Fill in HTTP In response body , yes REST Style controller ; It is @Controller and @ResponseBody Collection of .


Indicates that the return result of the method is written directly HTTP response body in

Generally used when asynchronously obtaining data , in use @RequestMapping after , The return value usually resolves to a jump path , add @responsebody The returned result will not be resolved to a jump path , Instead, write directly HTTP
response body in . For example, asynchronous acquisition json data , add @responsebody after , Will return directly json data .


Generic component , When components are difficult to classify , We can use this annotation for annotation .


amount to XML Medium , On top of the method , Not a class , It means to produce a bean, And give it to spring Administration .


byType mode . Configure the Bean Use it , Completion properties , Method assembly , It can be applied to class member variables , Methods and constructors , Complete automatic assembly .

When adding (required=false) Hour , Even if you can't find it bean No error .


When there are multiple of the same type Bean Hour , Available @Qualifier("name") To specify . And @Autowired Use together


If there is no bracketed content , default byName. And @Autowired Do something like that .


RequestMapping Is an annotation used to handle request address mapping ; Provide routing information , be responsible for URL reach Controller Mapping of concrete functions in , Available on classes or methods . Used on class , Indicates that all methods in the class that respond to requests take this address as the parent path .


Used in front of method parameters . example :

@RequestParam String a =request.getParameter("a").


Path variable . The parameter should be the same as the name in braces . example :


public String getByMacAddress(@PathVariable String macAddress){

  //do something;



Spring Profiles Provides a way to isolate application configurations , And make these configurations effective only in specific environments .

whatever @Component or @Configuration Can be @Profile sign , So as to limit the time to load it .



public class ProductionConfiguration {

// ...



Spring Boot The user-defined properties File mapping to entity bean in , such as config.properties file .



public class RocketMQConsumerProperties extends RocketMQProperties {

private boolean enabled = true;

private String consumerGroup;

private MessageModel messageModel = MessageModel.CLUSTERING;

private ConsumeFromWhere consumeFromWhere =

private int consumeThreadMin = 20;

private int consumeThreadMax = 64;

private int consumeConcurrentlyMaxSpan = 2000;

private int pullThresholdForQueue = 1000;

private int pullInterval = 0;

private int consumeMessageBatchMaxSize = 1;

private int pullBatchSize = 32;