Annotations in Spring Boot

0.0(0)
studied byStudied by 0 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/20

flashcard set

Earn XP

Description and Tags

Regarding Spring Boot Annotations for Semster

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

21 Terms

1
New cards

Anotations

  • Annotations are a form of meta data that provides data about a program

  • Provides Supplemental information about a program

  • Does not have a direct effect on the operation of the code

2
New cards

Types of Spring Boot Annotation

  • Spring Core Annotation

  • Spring Web Annotation

  • Spring Web Annotation

  • Spring Scheduling Annotation

  • Spring Data Annotation

  • Spring Bean Annotation

3
New cards

Core Annotation

  • These Annotations belong to the spring core module

  • They provide meta data to manage beans, dependency injection and control the application context without requiring a XML file

4
New cards

Core Annotation Example

  • Dependency Injection Relate Annotations

    • @Autowired

    • @Qualifier

    • @Bean

    • @Primary

    • @Lazy

  • Context Configuration Annotation

    • @Profile

    • @Import

    • @Import Resource

5
New cards

Dependency Injection related Annotations Code Example

//Field Injection

class Student{
@Autowired
Address address;}

//Constructor Injection

class Student{
@Autowired Student(){

//Setter Injection

class Student{

Address address;

@Autowired
void setAddress(Address ad){

address = ad;}

6
New cards

Context Configuration Annotations Code Example

@Component @Profile("developer") class Student{}

7
New cards

Spring Web Annotation

  • Spring Web Annotations are a part of the Spring MVC Framework

  • Used to build web applications and restful API

  • help to map HTTP request to Java methods, data binding, and define controller behaviour

8
New cards

Examples for Spring Web Annotation

  • @Request Mapping

  • @Response Body

  • @Path Variable

  • @Controller

9
New cards

Request Mapping Code

@Request mapping (value = "url")
class Demo{

@Get Request("url continuation")
some function to be executed
  • @Request Mapping is a class level annotation

  • Used to map HTTP request to their respective methods

  • It is a generic annotation as it can be used for any HTTP method like GET, POST, PUT, DELETE.

10
New cards

@Response Body

@Response Body

//Followed by similar code to before
  • It can be applied on both classes and methods

  • It tells the spring to return the method’s return value as the response body(ex : JSON)

11
New cards

@Controller

@Controller

//Followed by request mapping code
  • Marks a Java class as a web controller making it responsible for handling HTTP requests

12
New cards

Spring Boot Annotations

  • These simplify the development of restful API

  • Work on top of the spring framework and focus on auto configuration

13
New cards

Examples for Spring Boot Annotation

  • @Spring Boot Application

  • @Enable Auto Configuration

14
New cards

Auto-Configuration Conditions

  • @Conditional on Class

  • @Conditional on Bean

  • @Conditional on Property

  • @Conditional on Resource

  • @Conditional on Web Application

  • @Conditional on Not Web application

  • @Conditional

15
New cards

Example for @Spring Boot Application

@SpringBootApplication
public class MyApplication {
    public static void main(String[] args) {
        SpringApplication.run(MyApplication.class, args);
    }
}
  • This annotation is used to mark the main class of a spring boot application

  • It encapsulates @Configuration, @Enable Auto Configuration, @Component Scan

16
New cards

Spring Scheduling Annotation

  • Used to run tasks at a fixed interval or according to a cron expression

  • Helpful for automated tasks

17
New cards

Example for Scheduling Annotations

  • @Enable Async

  • @Enable Scheduling

  • @Scheduled

  • @Async

18
New cards

Spring Data Annotations

  • Used to map Java classes with database entities

  • Simplify data access when using JPA, Mongo DB or other spring modules

19
New cards

Spring Data Annotations Example

  • Common data Annotations

    • @Id

    • @Params

    • @Created By

    • @Last Modified By

    • @Created Date

  • Common Spring JPA Annotations

    • @Query

    • @Procedure

    • @Lock

  • Common Mongo Annotation

    • @Query

    • @Document

    • @Field

20
New cards

Spring Bean Annotation

  • Used to define and manage beans in a spring container

  • Essential for making objects available for dependency Injection

21
New cards

Examples for Spring Bean Annotation

  • @Component

  • @Component Scan

  • @Configuration