| アノテーション | 同等 | 説明 |
|---|---|---|
| 基本設定 | ||
| @SpringBootApplication | @Configuration + @EnableAutoConfiguration + @ComponentScan | Indicates a configuration class that declares one or more @Bean methods and also triggers auto-configuration and component scanning. |
| @EnableAutoConfiguration | Enable auto-configuration of the Spring Application Context, attempting to guess and configure beans that you are likely to need. Auto-configuration classes are usually applied based on your classpath and what beans you have defined. | |
| @ComponentScan | Configures component scanning directives for use with @Configuration classes. Provides support parallel with Spring XML’s <context:component-scan> element. | |
| RESTエンドポイント | ||
| @RestController | @Controller + @ResponseBody | Types that carry this annotation are treated as controllers where @RequestMapping methods assume @ResponseBody semantics by default. |
| リクエスト/ レスポンス | ||
| @PostMapping | @RequestMapping(method = RequestMethod.POST) | Annotation for mapping HTTP POST requests onto specific handler methods. |
| @GetMapping | @RequestMapping(method = RequestMethod.GET) | Annotation for mapping HTTP GET requests onto specific handler methods. |
| @PutMapping | @RequestMapping(method = RequestMethod.PUT) | Annotation for mapping HTTP PUT requests onto specific handler methods. |
| @DeleteMapping | @RequestMapping(method = RequestMethod.DELETE) | Annotation for mapping HTTP DELETE requests onto specific handler methods. |
| @PathVariable | Annotation which indicates that a method parameter should be bound to a URI template variable. | |
| @RequestParam | Annotation which indicates that a method parameter should be bound to a web request parameter. | |
| @RequestBody | Annotation indicating a method parameter should be bound to the body of the web request. | |
| コンポーネントタイプ | ||
| @Component | Indicates that an annotated class is a “component”. Such classes are considered as candidates for auto-detection when using annotation-based configuration and classpath scanning. Other class-level annotations may be considered as identifying a component as well, typically a special kind of component: e.g. the @Repository annotation or AspectJ’s @Aspect annotation. | |
| @Service | a specialization of @Component | Indicates that an annotated class is a “Service”, originally defined by Domain-Driven Design (Evans, 2003) as “an operation offered as an interface that stands alone in the model, with no encapsulated state.” |
| @Repository | a specialization of @Component | Indicates that an annotated class is a “Repository”, originally defined by Domain-Driven Design (Evans, 2003) as “a mechanism for encapsulating storage, retrieval, and search behavior which emulates a collection of objects”. |
| @Controller | a specialization of @Component | Indicates that an annotated class is a “Controller” (e.g. a web controller). This annotation serves as a specialization of @Component, allowing for implementation classes to be autodetected through classpath scanning. It is typically used in combination with annotated handler methods based on the RequestMapping annotation. |
| @Configuration | Indicates that a class declares one or more @Bean methods and may be processed by the Spring container to generate bean definitions and service requests for those beans at runtime. | |
| Beans | ||
| @Bean | Indicates that a method produces a bean to be managed by the Spring container. | |
| @Autowired | Marks a constructor, field, setter method, or config method as to be autowired by Spring’s dependency injection facilities. This is an alternative to the JSR-330 Inject annotation, adding required-vs-optional semantics. | |
| JPA関連 | ||
| @Entity | Specifies that the class is an entity. | |
| @Id | Specifies the primary key of an entity. | |
| @GeneratedValue | Provides for the specification of generation strategies for the values of primary keys. | |
| テスト | ||
| @SpringBootTest | Annotation that can be specified on a test class that runs Spring Boot based tests. | |
| @MockBean | Annotation that can be used to add mocks to a Spring ApplicationContext. | |
| @Validated | Variant of JSR-303’s Valid, supporting the specification of validation groups. Designed for convenient use with Spring’s JSR-303 support but not JSR-303 specific. | |
| その他 | ||
| @ConditionalOnJava | @Conditional that matches based on the JVM version the application is running on. | |
| Lombok | ||
| @Data | @Data is a convenient shortcut annotation that bundles the features of @ToString, @EqualsAndHashCode, @Getter / @Setter and @RequiredArgsConstructor together | |
| @NoArgsConstructor | @NoArgsConstructor will generate a constructor with no parameters. | |
| @AllArgsConstructor | @AllArgsConstructor generates a constructor with 1 parameter for each field in your class. |