@SpringBootApplication (Convenience annotations)

@SpringBootApplication = @EnableAutoConfiguration + @ComponentScan + @Configuration

@EnableAutoConfiguration

Configures beans based on what jars are in the classpath. Attempts to guess and configure beans that you are likely to need. Auto-configuration classes are usually applied based on your classpath and what beans you have defined.

@ComponentScan

Scan the beans so they are visible to IOC container.

@Configuration

Define bean definitions.

Stereotype Annotations (define the role of the class)

@Component

@Service

@RestController/@Controller

@Repository

Core Annotations

@Configuration, @Bean, @Autowired- The class can be used by Spring IOC container as a source of configuration.

@Qualifier or @Primary – when we have multiple data sources

@Lazy – By default the beans are eager loading.

@Value – values from properties file

@PropertySource

@ConfigurationProperties

@Profile – to load configuration for differing environment

@Scope – singleton, prototype, session, application, web

Rest API related Annotations

@RestController (Stereotype annotation)

@RequestMapping (Old annotation)

@GetMapping

@PostMapping

@PutMapping

@DeleteMapping

The above 4 are inherited from @RequestMapping

@RequsetBody (payload)

@PathVariable (input as parameter to the request itself)

@RequestParam

@PathVariable vs @RequestParam

If param is missing, @PathVariable will return error 404, in the case of @RequestParam, the param is optional.

@RestControllerAdvice and @ExceptionHandler

Spring Data JPA related Annotations

@Entity

@Table

@Id @GeneratedValue

@Column

@Transactional

Entity class relationships

@OnetoOne

@OnetoMany

@ManytoOne

@ManytoMany