SpringBoot Annotations CheatSheet
SpringBoot Annotations CheatSheet
@Configuration
- Defines a class as a Spring configuration class.
@ComponentScan
- Scans for Spring components (e.g., @Component, @Service, @Repository).
@Bean
- Declares a Spring-managed bean inside a @Configuration class.
@PropertySource
- Loads properties from external files into Springs Environment.
@Service
- Specialized @Component for service-layer beans.
@Repository
- Specialized @Component for DAO layer.
@Autowired
- Injects a bean automatically.
@Qualifier
- Specifies which bean to inject when multiple exist.
@Primary
- Marks a bean as the primary choice for dependency injection.
@GetMapping
- Handles GET requests.
@PostMapping
- Handles POST requests.
@PutMapping
- Handles PUT requests.
@DeleteMapping
- Handles DELETE requests.
@RequestParam
- Extracts query parameters.
@PathVariable
- Extracts a URI path variable.
@RequestBody
- Converts request JSON to Java object.
@ResponseBody
- Converts Java object to JSON response.
@Table(name='table_name')
- Specifies the table name for an entity.
@Id
- Marks a field as the primary key.
@GeneratedValue
- Auto-generates primary key values.
@Column(name='column_name')
- Maps an entity field to a database column.
@PreAuthorize
- Restricts access based on roles.
@Secured
- Restricts access to specific roles.
@RolesAllowed
- Restricts method access to specified roles.
@Rollback
- Rolls back transactions in test cases.
@EnableTransactionManagement
- Enables transaction management in Spring Boot.
@WebMvcTest
- Loads only the web layer for testing controllers.
@DataJpaTest
- Loads only the JPA-related components for database testing.
@MockBean
- Mocks a Spring bean for testing.
@ConditionalOnClass
- Configures beans only if a specific class is present.
@ConditionalOnProperty
- Configures beans based on property values.
@RefreshScope
- Enables runtime property refresh.