Annotations
Code Annotations
Spring framework: @SpringBootApplication- Indicates a configuration class that declares one or more @Bean methods and also triggers auto-configuration and component scanning. This is a convenience annotation that is equivalent to declaring @Configuration, @EnableAutoConfiguration, and @ComponentScan. @EnableEurekaServer- Used to make your Spring Boot application acts as a Eureka Server. @EnableZuulProxy- Sets up a Zuul server endpoint and installs some reverse proxy filters in it, so it can forward requests to backend servers. @EnableEurekaClient- Makes the app into both a Eureka "instance" (it registers itself) and a "client" (it can query the registry to locate other services). @Service- Serves as a specialization of @Component, allowing for implementation classes to be autodetected through classpath scanning. @Autowired- Provides more fine-grained control over where and how autowiring should be accomplished. The @Autowired annotation can be used to autowire bean on the setter method, constructor, a property, or methods with arbitrary names and/or multiple arguments. @ControllerAdvice- Allows handling exceptions across the whole application, not just to an individual controller. Checks if someone can catch the exception. @ExceptionHandler- Handles exceptions in specific handler classes and/or handler methods. @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 @ConfigurationProperties- Maps the entire .properties and yml file into an object easily. @Bean- Tells Spring that a method annotated with @Bean will return an object that should be registered as a bean in the Spring application context. @Value- Used for injecting values into fields in Spring-managed beans and it can be applied at the field or constructor/method parameter level. @Id- Marks a field in a model class as the primary key @Validated- Evaluated on a method or class level and validates the attributes and check correctness. @Component- Generic stereotype for any Spring-managed component. Mark the beans as Spring's managed components. @Profile- Mapping the bean to that particular profile. Simply takes the names of one (or multiple) profiles.
MongoDB: @Document- Identifies a domain object to be persisted to MongoDB @Indexed- Indicate that the annotated element represents a stereotype for the index. @DBRef- Indicates the annotated field is to be stored using a DBRef. @EnableMongoAuditing- MongoDbConfiguration for date. @CreatedDate- Declares a field as the one representing the date the entity containing the field was created. @LastModifiedDate- Declares a field as the one representing the date the entity containing the field was recently modified.
Controller: @RestContorller- Specialized version of the controller. It includes the @Controller and @ResponseBody annotations and as a result, simplifies the controller implementation @RequestMapping- Used to map web requests onto specific handler classes and/or handler methods. @RequestBody- Used to bind the HTTP request body with a domain object in method parameter or return type. @PathVariable- Used for data passed in the URI-RESTful services. @PostMapping- Handle the HTTP POST requests matched with given URI expression. @GetMapping- Maps HTTP GET requests onto specific handler methods. @PutMapping- Maps HTTP PUT requests onto specific handler methods. @DeleteMapping- Maps HTTP DELETE requests onto specific handler methods. @PatchMapping- Maps HTTP PATCH requests onto specific handler methods. @ResponseStatus- The status read-only property of the Response interface contains the status code of the response.
Swagger: @EnableSwagger2- Used to enable the Swagger2 (the UI) for Spring Boot application. @Api- Marks a class as a Swagger resource. Apply to all public methods of a class unless overridden by @APIMethod. @ApiOperation- Describes an operation or typically a HTTP method against a specific path. @ApiResponses- Wrapper to allow a list of multiple ApiResponse objects. @ApiResponse- Describes a possible response of an operation. @ApiModelProperty- Adds and manipulates data of a model property.
Lombok: @Data- A shortcut for @ToString, @EqualsAndHashCode, @Getter on all fields, @Setter on all non-final fields. @AllArgsConstructor- Generates constructors that take all arguments. @NoArgsConstructor- Generates constructors that take no arguments. @RequiredArgsConstructor- Generates constructors that take one argument per final / non-null field, or one argument for every field. @NonNull- Generate a null-check on condition/attribute. @Getter- Generate the default getter automatically.
Json: @JsonIgnore- Indicates that the annotated method or field is to be ignored by introspection-based serialization and deserialization functionality. That is, it should not be considered a "getter", "setter" or "creator". @JsonIgnoreProperties- Used to either suppress serialization of properties (during serialization) or ignore processing of JSON properties read (during deserialization). @JsonInclude- Indicate when the value of the annotated property (when used for a field, method, or constructor parameter), or all properties of the annotated class, is to be serialized. Without property values are always included, but by using this annotation one can specify simple exclusion rules to reduce the number of properties to write out. Logger: @Target- Indicates the contexts in which an annotation type is applicable. @Retention- Indicates how long annotations with the annotated type are to be retained. @Aspect- bean defined in your application context will be automatically detected by Spring and used to configure Spring AOP. @Component- considered as candidates for auto-detection when using annotation-based configuration and classpath scanning @Around- Advice that surrounds a join point such as a method invocation. @Before- Advice that executes before a join point, but which does not have the ability to prevent execution flow proceeding to the joining point.
General: @Override- Used when we override a method in a subclass. @Constraint- Marks an annotation as being a Bean Validation constraint. @NotBlank- The annotated element must not be null and must contain at least one non-whitespace character. @Email- The string has to be a well-formed email address. @Size- The annotated element size must be between the specified boundaries (included).
Test: @SpringBootTest- Can be specified on a test class that runs Spring Boot based tests. @Test- Provides a powerful tool for performing unit and regression testing.

Last updated
Was this helpful?