Difference between Component Service Repository Controller & RestController annotation | Code Decode

Описание к видео Difference between Component Service Repository Controller & RestController annotation | Code Decode

Spring boot Interview Question @Service @Repository @Component @Controller and @RestController differences

Udemy Course of Code Decode on Microservice k8s AWS CICD link:
https://openinapp.co/udemycourse

Course Description Video :
https://yt.openinapp.co/dmjvd

What is spring annotations
Spring Annotations are a form of metadata that provides data about a program.

Annotations are used to provide supplemental information about a program.

It does not have a direct effect on the operation of the code they annotate. It does not change the action of the compiled program.

@Component, @Service, @Repository, @Controller all these are stereotype annotations


What are stereotype annotation ?
A "stereotype annotation" is a special label or tag that developers put on classes to tell Spring something about the role or purpose of that class.

These annotations help the program understand how to treat and use these classes.

They're like quick notes attached to classes, providing information on what each class is meant to do in the application.



How Spring treats these stereotype annotations
Spring treats stereotype annotations differently from other annotations primarily in the context of component scanning and bean registration.

Here's how Spring treats stereotype annotations differently:

Automatic Bean Registration:

Classes annotated with stereotype annotations (e.g., @Component, @Service, @Repository, @Controller) are automatically registered as Spring beans during the component scanning process.

Other non-stereotype annotations or custom annotations generally don't trigger automatic bean registration.


How Spring treats these stereotype annotations

Component Scanning:

Stereotype annotations are explicitly considered during component scanning.

Spring looks for classes with these annotations and treats them differently based on their roles.

Other annotations might be used for specific purposes, but they might not trigger the same automatic bean registration and special treatment.


How Spring treats these stereotype annotations
Convention-Over-Configuration:

Stereotype annotations align with the convention-over-configuration principle in Spring. By using these annotations, developers adhere to a set of conventions that Spring can understand without requiring extensive configuration.

Other annotations might still require manual configuration to achieve similar results.

In summary, Spring treats stereotype annotations differently by providing them with special roles in the framework.

These annotations are designed to make development more straightforward by relying on conventions and minimizing the need for explicit configuration. They play a key role in the automatic discovery and management of beans within the Spring container.


How Spring treats these stereotype annotations
Example of non stereotype annotations :

@RequestMapping is not a stereotype annotation but is used for handling the mapping of requests.

@Autowired is not a stereotype annotation but rather an annotation for dependency injection.

Thus When Spring sees these annotations, it doesnt create beans automatically in container


@Component
We can use @Component annotation in our application to declare any class as the Spring’s managed components.

The classes under the @ComponentScan path annotated with @Component annotation will be registered as a Bean in Spring ApplicationContext.

You can use the instance of such bean using the @Autowired annotations.


Most Asked Core Java Interview Questions and Answers:    • Core Java frequently asked Interview ...  

Advance Java Interview Questions and Answers:    • Advance Java Interview Questions  

Java 8 Interview Questions and Answers:
   • Java 8 Interview Questions(New Features)  

Hibernate Interview Questions and Answers:
   • Hibernate Interview Questions Java  

Spring Boot Interview Questions and Answers:
   • Advance Java Interview Questions  

Angular Playlist:
   • Angular Course Introduction || Angular 8  
SQL Playlist:    • SQL Interview Questions and Answers  

GIT:    • GIT  

Subscriber and Follow Code Decode
Subscriber Code Decode: https://www.youtube.com/c/CodeDecode?...
LinkedIn :   / codedecodeyoutube  
Instagram:   / codedecode25  

#pathvariable #codedecode #requestparam

Комментарии

Информация по комментариям в разработке