Search This Blog

Friday, July 24, 2020

Java + SpringBoot + Mongodb -- Annotation



1.  @Configuration : --                                                                                                                                                                        indicates that the class has @Bean definition methods. So Spring         container can process the class and generate Spring Beans to be used in the application.

--> @Configuration annotation allows us to use annotations for dependency injection.

-- > @Configuration: Tags the class as a source of bean definitions for the application context.

 ----- > Loads this class before start the app.

2. @EnableMongoRepositories -- scans the current package for any interfaces that extend one of Spring Data’s repository interfaces. You can use its basePackageClasses=MyRepository.class to safely tell Spring Data MongoDB to scan a different root package by type if your project layout has multiple projects and it does not find your repositories.

3. @Document -- This annotion is used om MODEL
 --> This annotation marks a class as being a domain object that we want to persist to the database.
--> It also allows us to choose the name of the collection we want to use.

Note, that this annotation is the Mongo equivalent of @Entity in JPA.

4. @Bean -- annotation to declare beans in Java configuration classes.
-- > @Bean annotation indicates that the annotated method produces a bean to be managed by the Spring container. It is a direct analog of the <bean/> XML tag. @Bean supports most of the attributes offered by <bean/>, such as: init-methoddestroy-methodautowiringlazy-initdependency-checkdepends-onscope

--> Configuration classes can contain bean definition methods annotated with @Bean.
--> Bean is a method-level annotation and a direct analog of the XML <bean/> element. The annotation supports most of the attributes offered by <bean/>
--> @Bean Annotation is applied on a method to specify that it returns a bean to be managed by Spring context. Spring Bean annotation is usually declared in Configuration classes methods. In this case, bean methods may reference other @Bean methods in the same class by calling them directly.
--> @Bean annotation is widely used in annotation-driven spring applications.

5. 









@Slf4j
@Controller
@RequestMapping
@Autowired
@PostMapping(value = "/hotelDumpFromFile")
@ApiOperation
@ApiResponses(value = {
@ApiResponse(code = 200, message = "Successfully ingested Expedia Rapid HotelDetails "),
@ApiResponse(code = 500, message = "Unable to ingested Expedia Rapid HotelDetails")
})

@Slf4j
@Service

@Data
@Configuration
@Value("${spring.profiles.active}")
@PostConstruct
@Component
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonPropertyOrder
@JsonProperty("customerSessionId")
@Repository

@Builder
@Getter
@Setter
@EqualsAndHashCode(exclude = "updateDate")
@ToString
@JsonInclude(JsonInclude.Include.NON_NULL)
@Document(collection = "staticDumpHotel")
@Id
private String id;
private String hotelDetailId;
@Indexed
@Tolerate
Simply put, @ApiParam and @ApiModelProperty annotations add different metadata to Swagger. The @ApiParam annotation is for the parameters of an API resource request, whereas @ApiModelProperty is for properties of the model.

@ApiParam annotation is for use solely with the JAX-RS 1.x/2.x parameter annotations like @PathParam@QueryParam@HeaderParam@FormParam, and @BeanParam. Although swagger-core scans these annotations by default, we can use @ApiParam to add more details about the parameters or change the values as they are read from the code.

The @ApiParam annotation helps to specify the name, type, description (value), and example value of the parameter. Moreover, we can specify whether the parameter is required or optional.

The @ApiModelProperty annotation allows us to control Swagger-specific definitions such as description (value), name, data type, example values, and allowed values for the model properties.

Also, it offers additional filtering properties in case we want to hide the property in certain scenarios.


No comments:

Post a Comment