Difference between Component Service Repository Controller & RestController annotation | Code Decode
Вставка
- Опубліковано 6 жов 2024
- Spring boot Interview Question @Service @Repository @Component @Controller and @RestController differences
Udemy Course of Code Decode on Microservice k8s AWS CICD link:
openinapp.co/u...
Course Description Video :
yt.openinapp.c...
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 a...
Advance Java Interview Questions and Answers: • Advance Java Interview...
Java 8 Interview Questions and Answers:
• Java 8 Interview Quest...
Hibernate Interview Questions and Answers:
• Hibernate Interview Qu...
Spring Boot Interview Questions and Answers:
• Advance Java Interview...
Angular Playlist:
• Angular Course Introdu...
SQL Playlist: • SQL Interview Question...
GIT: • GIT
Subscriber and Follow Code Decode
Subscriber Code Decode: www.youtube.co...
LinkedIn : / codedecodeyoutube
Instagram: / codedecode25
#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😊
Hi Sidhanshu. Yeah we can wrap it quickly but we have covered a lot in this video. Starting from what are spring annotations, what are stereotype annotations, how they are different. Why these are stereotype and which annotations are not stereotypes. How to differentiate Between them. Then at end we came to differences.
You can directly skip to these stereotype annotations difference if you need.
Still you need to cut this video short by removing these initial imp interview questions, you can let us know. We will trim that part if that's not important.
Thanks for your feedback. Will be waiting for your response 👍👍
Learnt a lot in One video. Thank you so much from the heart.
you're welcome
thanks, waiting for this from long time
you're welcome
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
Thanks for covering such topics as well...Please create video for difference between @bean & @component...
Sure👍
Mam truely helpfulled ur explanation try to do more videos mam
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
Sure Ravi
awesome ❤
👍😊
Can you please make a udemy course by compiling all these spring boot and java question?
Sure we will do it soon 👍👍
Please do it it will be very helpful...
Sure Pramod 👍👍
Are @Configuration and @Bean stereotype annotations ?
Hi mam I want to go for mock interview. Kindly let me know the process
Please fill the google form given in the description
Hi Madam, could you please share the link of slides
Plz provide discount coupon for ur udemy course.... Right now its about 2k make it affordable plz
Hi Sale is going on you can check now using link giving in the description
Can you do udemy course for aws certifications also... It's much easier to understand your content than any others.
Sure👍👍
📈❤️🔥
Ohh now you also came with paid course one 😢
All those aws cloud things are not open source bro. They had to spend some dollars on that to even prepare the course.
Even your parents paid during your delivery, to get you into this world. Nothing comes for free bro. The sooner you accept this, the happier you will be. Cheers.
❤️❤️
It's true that even we have to pay a lot to aws to prepare this course. It takes a lot to create an end to end working project, which covers every thing a developer face in real world. And just to let you know, the tutor , the girl teaching this was 8 month pregnant when she was shooting this course. 399 is a small amount for you we feel Harsh. Please feel the pain required to create content for community.
@@CodeDecode Thanks for all the help guys, I have cracked a lot of interviews watching your content, have been following you since a long time. And congrats and all the best to ma'am for her pregnancy and delivery. Her child will be proud to have such a mother who helps unknown people to crack interviews and have a good career. Cheers to the team!