springboot Common annotations in are :

1,@SpringBootApplication

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
Boot
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.

2,@EnableAutoConfiguration

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 ;

3,@Configuration

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 .

4,@ComponentScan

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 .

5,@Repository

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 .

6,@Service

Generally used to decorate service Components of layer

7,@RestController

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 .

8,@ResponseBody

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 .

9,@Component

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

10,@Bean

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

11,@AutoWired

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 .

12,@Qualifier

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

13,@Resource(name="name",type="type")

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

14,@RequestMapping


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 .

15,@RequestParam

Used in front of method parameters . example :

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

16,@PathVariable

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

RequestMapping("user/get/mac/{macAddress}")

public String getByMacAddress(@PathVariable String macAddress){

  //do something;

}

17,@Profiles

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 .

@Configuration

@Profile("prod")

public class ProductionConfiguration {

// ...

}

18,@ConfigurationProperties

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

@Data

@ConfigurationProperties("rocketmq.consumer")

public class RocketMQConsumerProperties extends RocketMQProperties {

private boolean enabled = true;

private String consumerGroup;

private MessageModel messageModel = MessageModel.CLUSTERING;

private ConsumeFromWhere consumeFromWhere =
ConsumeFromWhere.CONSUME_FROM_LAST_OFFSET;

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;

}
 

Technology