Annotations in Spring Boot Interview Questions and Answers | Code Decode | Part -2

preview_player
Показать описание
In this video of code decode of Annotations in Spring boot Interview Questions and Answers we have covered some common interview questions regarding spring boot annotations

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

Course Description Video :

It’s the way to implement Dependency Injection in spring / spring boot application.

Container will provide the required bean to dependent bean at runtime

Spring provides annotation-based auto-wiring by providing @Autowired annotation.

It is used to autowire spring bean on setter methods, instance variable, and constructor.

When we use @Autowired annotation, the spring container auto-wires the bean by matching data-type.

How will container autowire the required bean in dependent bean at runtime ? It first need to create beans during startup so that it can provide beans at later stage.

How will container know who POJO / java class should be considered as bean and whom to ignore ?

@Component: It is a class-level annotation.

It is used to mark a Java class as a bean.

A Java class annotated with @Component is found during the classpath.

The Spring Framework pick it up and configure it in the application context as a Spring Bean.

It is a generic stereotype for any Spring-managed component. The specializations are @Controller, @Service, @Repository

The @Controller is a class-level annotation.

It is a specialization of @Component.

It marks a class as a web request handler. It is often used to serve web pages. It is used in conjunction with @RequestMapping annotation.

We also use @RestController when we need to send response in JSON format directly.

By default, @Controller returns a string that indicates which route to redirect. Its used mostly with JSPs. It returns URL to new JSP page where it has to be redirected

They are nothing but the specialized form of @Component annotation for certain situations. Instead of using @Component on a controller class in Spring MVC, we use @Controller, which is more readable and appropriate.

The @Controller is a class-level annotation.

It is a specialization of @Component.

It marks a class as a web request handler. It is often used to serve web pages. It is used in conjunction with @RequestMapping annotation.

We also use @RestController when we need to send response in JSON format directly.

They are nothing but the specialized form of @Component annotation for certain situations. Instead of using @Component on a controller class in Spring MVC, we use @Controller, which is more readable and appropriate.

By using @Controller annotation we do two things,
We declare that this class is a Spring bean and should be created and maintained by Spring ApplicationContext,
We indicate that its a controller in MVC setup. This latter property is used by web-specific tools and functionalities.

DispatcherServlet will look for @RequestMapping on classes that are annotated using @Controller but not with @Component.

This means @Component and @Controller are the same with respect to bean creation and dependency injection but @Controller is a specialized form of @Component. Even if you replace @Controller annotation with @Compoenent, Spring can automatically detect and register the controller class but it may not work as you expect with respect to request mapping.

It is also used at class level.

It is a specialization of @Component.

It tells the Spring that class contains the business logic.

But at the end The main task of this annotation is also to mark the class capable to become a bean in Spring container similar to component. We can use @component also and it will work the same as this annotation does.

Subscriber and Follow Code Decode

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

for making our life easy u go girl....

akankshasharma
Автор

Please also make a third part with more annotations. Thanks for making these videos really helpful in cracking interviews.

krishnalakshmi
Автор

Anybody having basic language knowledge can watch your video and gain industry level knowledge, each and every concept is explained in detail . Can you also make detail video on apache kafka

pranjalsingh
Автор

Addicted with these videos like Instagram reels . Pl. make the third part of the remaining annotations.

Amityadav-jrrg
Автор

You are awesome.. awesome in making words simpler and understandable..thanks a lot

revatisrr
Автор

Thanks for making this video this is the best for beginners

murgeshhiremath
Автор

Am Fallen in Love with #CodeDecode, I am from Mech Background, working in IT field currently. When I start your playlist, You will never fail in making me understand the things in a perfect way. Thanks a Lott💌. Want more Videos.

pnkirankumar
Автор

Yes definitely, It is very helpful and please make 3rd part as well. :)

aishwaryathakkar
Автор

nicely curated and well explained, looking for more videos.

veerayuvakishore
Автор

Thank you so much. Best channel to prepare for an interview on springboot and java

Ghost_k
Автор

Great and very helpful. Thanks a lot 🙏🏾

RRamasami
Автор

very informative, it clears all the doubts plz make 3rd part as well

yatharthyadav
Автор

Awesome. Please make more videos on spring boot annotations

Pratyush.K.R
Автор

Please make the 3rd part as well. The videos are really very helpful. Thank you.

nikitamehto
Автор

Thanks mam please upload more annotations

amitjoshi
Автор

Hi CodeEcode, wonderful explanation. Please do add thre remaining annotations also.It will be very helpfull

sravantigopisetty
Автор

Thanks maam, please show us more annotations

akashsaha
Автор

very understandable explanation thanks !!!! please make videos on rest of the annotations

poojaranavare
Автор

Thanks for this wonderful and informative video. Please make video for the left out annotations.

GauravKumar-lqql
Автор

Hi pls add third part of this .. 😊waiting

kavithaeswaradoss
visit shbcf.ru