Spring Boot Annotations

In this blog, I have listed the most common spring boot annotations that we are using in the projects. Please refer https://samplecoder.com/how-to-create-a-spring-boot-application-in-sts/ to know, how to create your first spring boot application.

Spring Annotations

  • @SpringBootApplication
    • This annotation commonly used at the class level. And that class should be a main class. If the class which is annotated with @SpringBootApplication it consider as starting point of the spring boot application. This annotation is combination of @EnableAutoCofiguration, @ComponentScan, and @Configuration
  • @Component
    • This is a class level annotation. If any class is annotated with @Component spring, consider as its component class and create the bean at the time of application starting.
  • @ComponentScan
    • This is a class level annotation, normally we use it for configuration. By passing the package name, we tell to spring that should scan all the component class those are there in a given package.
  • @EnableAutoConfiguration
    • This is a class level annotation, Its enable spring boot to do auto configuration based on the dependency those are we added.
  • @Configuration
    • This is a class level annotation, this contains the bean configurations.
  • @Autowired
    • This is the property and a constructor level annotation. It helps to inject the bean automatically based on its types at the run time.
  • @Service
    • This is a class level annotation, for creating the service layer
  • @Repository
    • This is a class level annotation, for creating the Repository layer
  • @Bean
    • This is method level annotation, used for creating or config the bean
  • @Scope
    • Used for defining the scope of the bean, the default scope is a singleton.
  • @Value
    • Its property level annotation. Used to load the values from an application properties file by passing the property name as parameter.

REST Annotations

  • @RestController
  • @Controller
  • @RequestMapping
  • @GetMapping
  • @PostMapping
  • @DeleteMapping
  • @RequestBody
  • @ResponseBody
  • @PathVariable
  • @RequestParam

JSON annotations

  • @JsonAutoDetect
  • @JsonIgnoreProperties(ignoreUnknown = true)

JPA annotations

  • @Entity
  • @Table
  • @Id
  • @GeneratedValue(strategy = GenerationType.IDENTITY)
  • @OneToMany
  • @ManyToOne
  • @OneToOne
  • @Column
  • @JoinColumn
  • @Transient
  • @Transactional
  • @Modifying
  • @Query
  • @NamedQueries
  • @NamedQuery