Blog Detail

  • Home
  • Spring Boot Annotations

Spring Boot Annotations

In this blog I have list out the most common annotations that we are using in Spring Boot Project.

Spring Annotations

  • @SpringBootApplication
    • This annotation commonly used at 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 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 class level annotation, normally we using it for configuration. By passing the package name, we tell to spring that should scan all the component class those are there in given package
  • @EnableAutoConfiguration
    • This is class level annotation, Its enable spring boot to do auto configuration based on the dependency those are we added.
  • @Configuration
    • This is class level annotation, this contains the bean configurations.
  • @Autowired
    • This is property and constructor level annotation. Its helps to inject the bean automatically based on its types at the run time.
  • @Service
    • This is class level annotation, for creating the service layer
  • @Repository
    • This is class level annotation, for creating the Repository layer
  • @Bean
    • This is method level annotation, used for creating or config the bean
  • @Scope
    • used for define the scope of bean, default scope is singleton.
  • @Value
    • Its property level annotation. used for load the values from 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

Write a comment