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

preview_player
Показать описание
Spring boot Interview Question @Service @Repository @Component @Controller and @RestController differences

Udemy Course of Code Decode on Microservice k8s AWS CICD link:

Course Description Video :

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.

Java 8 Interview Questions and Answers:

Hibernate Interview Questions and Answers:

Spring Boot Interview Questions and Answers:

Angular Playlist:

Subscriber and Follow Code Decode

#pathvariable #codedecode #requestparam
Рекомендации по теме
Комментарии
Автор

No offence. Just a positive feedback: you could have wrap up this topic in 5min video. Felt like same thing is repeated in the video. Hoping to get these type of great content from you but in a time limited good content. Thanks😊

sidhanshuraghuvanshi
Автор

Learnt a lot in One video. Thank you so much from the heart.

trailblazer
Автор

thanks, waiting for this from long time

amarthyaseshu
Автор

You said, until now no differences between @Component and @Service, please specify the Spring version so if a change happen we can which version you talk about. Thanks a lot

samahmahdi
Автор

Thanks for covering such topics as well...Please create video for difference between @bean & @component...

pramodpawar
Автор

Mam truely helpfulled ur explanation try to do more videos mam

geethak
Автор

Could you please make video on oauth2.0 with scope and jwt creation along permission management, in short a security video which will be helpful

_ravi_kumar_gupta
Автор

Can you please make a udemy course by compiling all these spring boot and java question?

ShubhamPatil-igqe
Автор

Are @Configuration and @Bean stereotype annotations ?

pk
Автор

Hi mam I want to go for mock interview. Kindly let me know the process

gyaanbhandaar
Автор

Hi Madam, could you please share the link of slides

Atul_Shegokar
Автор

Plz provide discount coupon for ur udemy course.... Right now its about 2k make it affordable plz

saurabhparashar
Автор

Can you do udemy course for aws certifications also... It's much easier to understand your content than any others.

vinayuddagiri
Автор

Ohh now you also came with paid course one 😢

harshbaghel