Annotations in Spring boot with Explanation| Spring boot Interview Questions and Answers Code Decode

Описание к видео Annotations in Spring boot with Explanation| Spring boot Interview Questions and Answers Code Decode

In this video of code decode we have explained about Annotations in Spring boot. Annotations in spring boot is very important Interview in Spring boot interview questions and answers.

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

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

Spring boot annotations

Spring Boot is the most popular Java framework. Spring Boot built upon spring framework. It minimize the amount of configuration and boilerplate code you need to get started.

The Java provided support for Annotations from Java 5.0.
Prior to that, the behavior of the Spring Framework was largely controlled through XML configuration. Today, the use of annotations provide us tremendous capabilities in how we configure the Spring Framework.

Spring Annotations are a form of metadata. 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.

@SpringBootApplication

It is a combination of three annotations
@EnableAutoConfiguration,
@ComponentScan, and
@Configuration.

if you see at their parent packages:
org.springframework.boot.autoconfigure.EnableAutoConfiguration
org.springframework.context.annotation.Configuration
org.springframework.context.annotation.ComponentScan

So we can say this Spring boot annotations can’t exist on its own. It needs spring framework annotations to work.

Annotations on annotations-@Target

@Target tag is used to specify at which type, the annotation is used.

The java.lang.annotation.ElementType enum declares many constants to specify the type of element where annotation is to be applied such as TYPE, METHOD, FIELD etc. Let's see the constants of ElementType enum:

Element Types Where the annotation can be applied
TYPE class, interface or enumeration
FIELD fields
METHOD methods
CONSTRUCTOR constructors
LOCAL_VARIABLE local variables
ANNOTATION_TYPE annotation type
PARAMETER parameter

Annotations on annotations-@Retention

@Retention annotation is used to specify to what level annotation will be available.

RetentionPolicy.SOURCE - refers to the source code, discarded during compilation. It will not be available in the compiled class.

RetentionPolicy.CLASS refers to the .class file, available to java compiler but not to JVM . It is included in the class file.

RetentionPolicy.RUNTIME refers to the runtime, available to java compiler and JVM .

Annotations on annotations-@Inherited @Documented

By default, annotations are not inherited to subclasses. The @Inherited annotation marks the annotation to be inherited to subclasses.

The @Documented Marks the annotation for inclusion in the documentation.

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

Point to note-
The main application class is also a bean, as it's annotated with @Configuration, which is a @Component.

@EnableAutoConfiguration

The @EnableAutoConfiguration annotation enables Spring Boot to auto-configure the application context. Therefore, it automatically creates and registers beans based on both the included jar files in the classpath and the beans defined by us, implicitly @EnableAutoConfiguration annotation, which makes Spring Boot create many beans automatically, relying on the dependencies in pom.xml file.

For example, when we define the spring-boot-starter-web dependency in our classpath, Spring boot auto-configures Tomcat and Spring MVC.

If you have added tomcat-embedded.jar then it tries to intellectually configure TomcatServletWebServerFactory if you do not have specified explicitly as ServletWebServerFactory bean. Hence, this auto-configuration has less precedence in case we define our own configurations.



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  

#codedecode #Springbootannotations #springbootinterviewquestionsandanswers

Комментарии

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