Spring Boot Core Annotations Cheatsheet 2026
Comprehensive guide to core Spring Framework and Spring Boot annotations including Stereotypes, REST Controllers, DI, Data/JPA, and Configuration.
Interactive Skill Mastery
Mark commands as learned to build your customized reference tracker. Retained locally in this browser.
Stereotypes
When to Use
When building Spring Boot applications to define component beans, configure mapping controllers, or structure database JPA repositories.
Common Mistakes
Placing annotations on classes outside Spring's package component-scan search scope, causing BeanCreationExceptions.
Shortcut / Pro-Tip
Use specialized annotations like @RestController and @GetMapping to keep controller code clean and concise.Example
@SpringBootApplication
public class UserResource {
// Controller metadata
}Output Example
// Registers structural Java configuration or bean in Spring's Application ContextWhen to Use
When building Spring Boot applications to define component beans, configure mapping controllers, or structure database JPA repositories.
Common Mistakes
Placing annotations on classes outside Spring's package component-scan search scope, causing BeanCreationExceptions.
Shortcut / Pro-Tip
Use specialized annotations like @RestController and @GetMapping to keep controller code clean and concise.Example
@Component
public class UserResource {
// Controller metadata
}Output Example
// Registers structural Java configuration or bean in Spring's Application ContextWhen to Use
When building Spring Boot applications to define component beans, configure mapping controllers, or structure database JPA repositories.
Common Mistakes
Placing annotations on classes outside Spring's package component-scan search scope, causing BeanCreationExceptions.
Shortcut / Pro-Tip
Use specialized annotations like @RestController and @GetMapping to keep controller code clean and concise.Example
@Service
public class UserResource {
// Controller metadata
}Output Example
// Registers structural Java configuration or bean in Spring's Application ContextWhen to Use
When building Spring Boot applications to define component beans, configure mapping controllers, or structure database JPA repositories.
Common Mistakes
Placing annotations on classes outside Spring's package component-scan search scope, causing BeanCreationExceptions.
Shortcut / Pro-Tip
Use specialized annotations like @RestController and @GetMapping to keep controller code clean and concise.Example
@Repository
public class UserResource {
// Controller metadata
}Output Example
// Registers structural Java configuration or bean in Spring's Application ContextSpring MVC & REST
When to Use
When exposing RESTful API endpoints and binding web query paths to specific Java controller methods.
Common Mistakes
Forgetting to annotate methods with @ResponseBody (or failing to use @RestController), returning raw strings instead of serialized JSON.
Shortcut / Pro-Tip
Leverage @PathVariable for REST paths and @RequestParam for clean query key-value parameter bindings.Example
@RestController
public class UserResource {
// Controller metadata
}Output Example
// Registers structural Java configuration or bean in Spring's Application ContextWhen to Use
When exposing RESTful API endpoints and binding web query paths to specific Java controller methods.
Common Mistakes
Forgetting to annotate methods with @ResponseBody (or failing to use @RestController), returning raw strings instead of serialized JSON.
Shortcut / Pro-Tip
Leverage @PathVariable for REST paths and @RequestParam for clean query key-value parameter bindings.Example
@GetMapping("/path")
public class UserResource {
// Controller metadata
}Output Example
// Registers structural Java configuration or bean in Spring's Application ContextWhen to Use
When exposing RESTful API endpoints and binding web query paths to specific Java controller methods.
Common Mistakes
Forgetting to annotate methods with @ResponseBody (or failing to use @RestController), returning raw strings instead of serialized JSON.
Shortcut / Pro-Tip
Leverage @PathVariable for REST paths and @RequestParam for clean query key-value parameter bindings.Example
@PostMapping("/path")
public class UserResource {
// Controller metadata
}Output Example
// Registers structural Java configuration or bean in Spring's Application ContextWhen to Use
When building Spring Boot applications to define component beans, configure mapping controllers, or structure database JPA repositories.
Common Mistakes
Placing annotations on classes outside Spring's package component-scan search scope, causing BeanCreationExceptions.
Shortcut / Pro-Tip
Use specialized annotations like @RestController and @GetMapping to keep controller code clean and concise.Example
@PathVariable
public class UserResource {
// Controller metadata
}Output Example
// Registers structural Java configuration or bean in Spring's Application ContextWhen to Use
When building Spring Boot applications to define component beans, configure mapping controllers, or structure database JPA repositories.
Common Mistakes
Placing annotations on classes outside Spring's package component-scan search scope, causing BeanCreationExceptions.
Shortcut / Pro-Tip
Use specialized annotations like @RestController and @GetMapping to keep controller code clean and concise.Example
@RequestParam
public class UserResource {
// Controller metadata
}Output Example
// Registers structural Java configuration or bean in Spring's Application ContextWhen to Use
When building Spring Boot applications to define component beans, configure mapping controllers, or structure database JPA repositories.
Common Mistakes
Placing annotations on classes outside Spring's package component-scan search scope, causing BeanCreationExceptions.
Shortcut / Pro-Tip
Use specialized annotations like @RestController and @GetMapping to keep controller code clean and concise.Example
@RequestBody
public class UserResource {
// Controller metadata
}Output Example
// Registers structural Java configuration or bean in Spring's Application ContextDI & Configuration
When to Use
When implementing Dependency Injection (DI) to automatically wire collaborating components and manage object lifecycles.
Common Mistakes
Creating circular dependencies between Spring beans, which crashes the application context at boot time.
Shortcut / Pro-Tip
Prefer constructor-based dependency injection over field injection for clean unit testing and immutability.Example
@Autowired
public class UserResource {
// Controller metadata
}Output Example
// Registers structural Java configuration or bean in Spring's Application ContextWhen to Use
When building Spring Boot applications to define component beans, configure mapping controllers, or structure database JPA repositories.
Common Mistakes
Placing annotations on classes outside Spring's package component-scan search scope, causing BeanCreationExceptions.
Shortcut / Pro-Tip
Use specialized annotations like @RestController and @GetMapping to keep controller code clean and concise.Example
@Qualifier("beanName")
public class UserResource {
// Controller metadata
}Output Example
// Registers structural Java configuration or bean in Spring's Application ContextWhen to Use
When implementing Dependency Injection (DI) to automatically wire collaborating components and manage object lifecycles.
Common Mistakes
Creating circular dependencies between Spring beans, which crashes the application context at boot time.
Shortcut / Pro-Tip
Prefer constructor-based dependency injection over field injection for clean unit testing and immutability.Example
@Configuration
public class UserResource {
// Controller metadata
}Output Example
// Registers structural Java configuration or bean in Spring's Application ContextWhen to Use
When implementing Dependency Injection (DI) to automatically wire collaborating components and manage object lifecycles.
Common Mistakes
Creating circular dependencies between Spring beans, which crashes the application context at boot time.
Shortcut / Pro-Tip
Prefer constructor-based dependency injection over field injection for clean unit testing and immutability.Example
@Bean
public class UserResource {
// Controller metadata
}Output Example
// Registers structural Java configuration or bean in Spring's Application ContextWhen to Use
When building Spring Boot applications to define component beans, configure mapping controllers, or structure database JPA repositories.
Common Mistakes
Placing annotations on classes outside Spring's package component-scan search scope, causing BeanCreationExceptions.
Shortcut / Pro-Tip
Use specialized annotations like @RestController and @GetMapping to keep controller code clean and concise.Example
@Value("${property.name}")
public class UserResource {
// Controller metadata
}Output Example
// Registers structural Java configuration or bean in Spring's Application ContextSpring Data JPA
When to Use
When building Spring Boot applications to define component beans, configure mapping controllers, or structure database JPA repositories.
Common Mistakes
Placing annotations on classes outside Spring's package component-scan search scope, causing BeanCreationExceptions.
Shortcut / Pro-Tip
Use specialized annotations like @RestController and @GetMapping to keep controller code clean and concise.Example
@Entity
public class UserResource {
// Controller metadata
}Output Example
// Registers structural Java configuration or bean in Spring's Application ContextWhen to Use
When building Spring Boot applications to define component beans, configure mapping controllers, or structure database JPA repositories.
Common Mistakes
Placing annotations on classes outside Spring's package component-scan search scope, causing BeanCreationExceptions.
Shortcut / Pro-Tip
Use specialized annotations like @RestController and @GetMapping to keep controller code clean and concise.Example
@Table(name = "users")
public class UserResource {
// Controller metadata
}Output Example
// Registers structural Java configuration or bean in Spring's Application ContextWhen to Use
When building Spring Boot applications to define component beans, configure mapping controllers, or structure database JPA repositories.
Common Mistakes
Placing annotations on classes outside Spring's package component-scan search scope, causing BeanCreationExceptions.
Shortcut / Pro-Tip
Use specialized annotations like @RestController and @GetMapping to keep controller code clean and concise.Example
@Id
public class UserResource {
// Controller metadata
}Output Example
// Registers structural Java configuration or bean in Spring's Application ContextWhen to Use
When building Spring Boot applications to define component beans, configure mapping controllers, or structure database JPA repositories.
Common Mistakes
Placing annotations on classes outside Spring's package component-scan search scope, causing BeanCreationExceptions.
Shortcut / Pro-Tip
Use specialized annotations like @RestController and @GetMapping to keep controller code clean and concise.Example
@GeneratedValue(strategy = GenerationType.IDENTITY)
public class UserResource {
// Controller metadata
}Output Example
// Registers structural Java configuration or bean in Spring's Application ContextWhen to Use
When building Spring Boot applications to define component beans, configure mapping controllers, or structure database JPA repositories.
Common Mistakes
Placing annotations on classes outside Spring's package component-scan search scope, causing BeanCreationExceptions.
Shortcut / Pro-Tip
Use specialized annotations like @RestController and @GetMapping to keep controller code clean and concise.Example
@OneToMany / @ManyToOne
public class UserResource {
// Controller metadata
}Output Example
// Registers structural Java configuration or bean in Spring's Application ContextTesting
When to Use
When building Spring Boot applications to define component beans, configure mapping controllers, or structure database JPA repositories.
Common Mistakes
Placing annotations on classes outside Spring's package component-scan search scope, causing BeanCreationExceptions.
Shortcut / Pro-Tip
Use specialized annotations like @RestController and @GetMapping to keep controller code clean and concise.Example
@SpringBootTest
public class UserResource {
// Controller metadata
}Output Example
// Registers structural Java configuration or bean in Spring's Application ContextWhen to Use
When implementing Dependency Injection (DI) to automatically wire collaborating components and manage object lifecycles.
Common Mistakes
Creating circular dependencies between Spring beans, which crashes the application context at boot time.
Shortcut / Pro-Tip
Prefer constructor-based dependency injection over field injection for clean unit testing and immutability.Example
@MockBean
public class UserResource {
// Controller metadata
}Output Example
// Registers structural Java configuration or bean in Spring's Application ContextSpring Boot Annotations Best Practices
1Prefer Constructor Injection
Avoid field injection with @Autowired. Use constructor injection instead to make classes immutable, clear in dependencies, and easier to unit test without Spring runner.
2Keep Stereotypes Semantic
Use @Service for business logic and @Repository for data access rather than general @Component to benefit from specialized Spring middleware features.
3Define Custom Config Properties
Use @ConfigurationProperties instead of scattering multiple @Value annotations. It provides type-safety, validation, and structures configuration properties.
4Leverage Profile-Specific Beans
Use @Profile to configure environment-specific beans (e.g. @Profile("prod") vs @Profile("dev")), keeping environments clean and isolated.
5Minimize Heavy Auto-Configurations
Exclude unneeded auto-configurations to optimize application boot times and reduce memory overhead.
Common Spring Boot Annotations Errors & Solutions
NoSuchBeanDefinitionException
Spring is unable to find a bean matching the injection target. Solution: Ensure the target class has a stereotype annotation and resides inside a scanned package.
CircularDependencyException
Two or more beans depend on each other, creating an infinite loading loop. Solution: Restructure dependencies or resolve them lazily using @Lazy.
BeanCreationException
An error occurred while Spring was constructing a bean at startup. Solution: Inspect the root cause stack trace to find configuration, DB connection, or property typos.
HttpMediaTypeNotSupportedException
The incoming request media type is invalid. Solution: Ensure the client sends 'Content-Type: application/json' and the controller declares appropriate consumes parameters.
PropertyAccessException
A configuration key is missing or cannot be cast to the specified Java field type. Solution: Declare default property values or check application.properties structures.
Common Spring Boot Annotations Interview Questions
Q1What is @SpringBootApplication and what does it combine?
It is a convenience annotation that combines @Configuration (enables Java-based config), @EnableAutoConfiguration (enables Spring Boot auto-config), and @ComponentScan (scans for beans).
Q2How do @Component, @Service, and @Repository differ?
They are all stereotype annotations. @Component is the general bean candidate. @Service specializes it for business services, and @Repository specializes it for database DAOs, including translation of database exceptions.
Q3What is the purpose of @Autowired?
It enables automatic dependency injection. Spring resolves and injects collaborating beans into constructors, setter methods, or fields automatically.
Q4What is the difference between @Controller and @RestController?
@Controller is used to define web controllers that render traditional views (like Thymeleaf templates). @RestController combines @Controller and @ResponseBody, returning serialized JSON/XML data directly.
Q5How does @Bean differ from @Component?
@Component is class-level and automatically scanned by Spring. @Bean is method-level inside a @Configuration class, giving you explicit control over bean instantiation.
Related Resources
REST API Tester
Test API routes and endpoints directly in your browser with full request controls.
JSON Formatter & Validator
Beautify, validate, and minify JSON structures instantly.
Best Free Online Developer Tools
An expert review of must-have online utilities for developers.
Git Cheatsheet
Essential command reference for local and remote version control repositories.
Generated from LearnHubly Developer Cheatsheets
Access interactive sandbox tests, tools, and developer code bases at https://www.learnhubly.com