Spring Boot Annotations Explained

What are Spring Boot annotations? They are markers (like @RestController or @Service) that tell Spring what a class or method does, so Spring can create objects, connect them, map URLs, validate data and manage transactions for you. Learn them by layer: setup (@SpringBootApplication), web (@RestController, @GetMapping), business (@Service, @Transactional), data (@Entity, @Repository), validation (@Valid, @NotBlank) and testing (@SpringBootTest).
This guide from VibrantMinds Technologies in Pune explains the 40+ Spring Boot annotations freshers actually meet, with examples, a cheat sheet and interview answers. It is written for anyone searching Spring Boot annotations, Spring Boot annotations list with examples, Spring Boot annotations for freshers, Spring Boot annotations interview questions, @RestController vs @Controller, @Component vs @Service vs @Repository, @Autowired vs constructor injection, @RequestParam vs @PathVariable, Spring Boot annotations cheat sheet or a free IT job WhatsApp group for Java freshers in Pune.
Takeaway | Detail |
|---|---|
Annotations are instructions to Spring | They say what a class is and how it should behave. |
Learn them by layer | Web, service, repository, entity, validation, tests. |
Prefer constructor injection | It is clearer and easier to test than field |
|
|
Know the stereotype differences |
|
| It works through proxies, so self-calls and private methods can surprise you. |
Explain with a flow | Request, controller, service, repository, database. |
THE BIG PICTURE: ANNOTATIONS BY LAYER
GROUP 1: SETUP AND CONFIGURATION
Annotation | What it does |
|---|---|
| Marks the main class. Combines |
| Lets Spring Boot configure beans automatically based on your dependencies. |
| Tells Spring which packages to scan for components. |
| Marks a class that defines beans. |
| Marks a method whose return value becomes a Spring-managed bean. |
java
java
Common problem: classes outside the main class’s package (or its sub-packages) are not scanned, which causes NoSuchBeanDefinitionException. Keep the main class in the root package.
GROUP 2: STEREOTYPE AND DEPENDENCY INJECTION
Stereotype annotations
Annotation | Use for | Extra meaning |
|---|---|---|
| Any generic Spring-managed class | Base stereotype |
| Business logic classes | Marks the service layer |
| Data access classes | Also translates persistence exceptions |
| MVC controllers returning views | Web layer |
| REST API controllers |
|
@Component vs @Service vs @Repository: all create Spring beans. The specific ones document the role of the class, and @Repository adds exception translation.
Dependency injection annotations
Annotation | What it does |
|---|---|
| Asks Spring to inject a dependency |
| Chooses a specific bean when several match |
| Marks the default bean when several match |
| Creates the bean only when first needed |
| Sets the bean scope (singleton by default, prototype and others) |
| Runs a method after the bean is created and dependencies are injected |
Constructor injection (recommended)
java
Field injection (works, but less preferred)
java
Point | Constructor injection | Field injection |
|---|---|---|
Testing | Easy, pass a mock in the constructor | Needs reflection or Spring |
Immutability | Fields can be | Cannot be |
Required dependencies | Clear and enforced | Hidden |
Verdict | Recommended | Avoid in new code |
Two beans of the same type
java
GROUP 3: WEB AND REST
Annotation | What it does |
|---|---|
| Class handles HTTP requests and returns data (JSON) directly |
| Maps a URL path (class or method level) |
| Handles GET requests |
| Handles POST requests |
| Handles PUT requests |
| Handles PATCH requests |
| Handles DELETE requests |
| Reads a value from the URL path |
| Reads a query parameter |
| Converts the JSON body into a Java object |
| Writes the return value to the response body |
| Sets the HTTP status code |
| Reads a header value |
| Allows cross-origin requests (for example, from a React app) |
A full REST controller
java
@PathVariable vs @RequestParam
Point |
|
|
|---|---|---|
Where the value is | In the URL path | In the query string |
Example URL |
|
|
Typical use | Identify one resource | Filter, sort, paginate |
@Controller vs @RestController
Point |
|
|
|---|---|---|
Returns | A view name (HTML page) by default | Data written to the response body |
Needs | Yes, for JSON | No, it’s built in |
Used for | Server-rendered pages | REST APIs |
GROUP 4: EXCEPTION HANDLING
Annotation | What it does |
|---|---|
| Handles a specific exception |
| Applies exception handling across all controllers |
| Maps an exception or method to an HTTP status |
java
Benefit: one place for clean, consistent error responses instead of repeated try/catch blocks.
GROUP 5: DATA AND JPA
Annotation | What it does |
|---|---|
| Maps a class to a database table |
| Sets the table name |
| Marks the primary key |
| Auto-generates the key |
| Customises a column (name, length, nullable, unique) |
| Defines relationships |
| Defines the foreign key column |
| Stores an enum as text or number |
| Excludes a field from persistence |
| Writes a custom query on a repository method |
java
java
Note: a Spring Data repository interface doesn’t need @Repository because Spring Data detects it, though adding it is harmless.
GROUP 6: TRANSACTIONS
Annotation | What it does |
|---|---|
| Runs a method inside a database transaction, committing on success and rolling back on failure |
| Enables transaction support (Spring Boot usually configures it automatically) |
java
Rules freshers should remember
Rule | Why it matters |
|---|---|
Rollback happens by default for unchecked exceptions (RuntimeException and Error) | Checked exceptions don’t roll back unless you configure |
It works through proxies | Calling a |
Use it on public methods in Spring-managed beans | Private methods are not intercepted |
Put it on the service layer | Business operations, not controllers, define the transaction boundary |
| Useful for read-only methods |
GROUP 7: VALIDATION
Add the validation starter dependency. In Spring Boot 3 these live in jakarta.validation.constraints.
Annotation | Checks |
|---|---|
| Triggers validation on an object |
| Spring’s variant, supports validation groups and method-level validation |
| Not null |
| Not null and not only spaces (for strings) |
| Not null and not empty |
| Length or size limits |
| Numeric limits |
| Email format |
| Matches a regular expression |
| Greater than zero |
java
java
If validation fails, Spring throws MethodArgumentNotValidException, which your @RestControllerAdvice can turn into a clean 400 response.
GROUP 8: PROPERTIES AND PROFILES
Annotation | What it does |
|---|---|
| Injects a single property value |
| Binds a group of properties to a class |
| Loads an extra properties file |
| Activates a bean only for a given profile |
java
java
java
Security habit: keep passwords and keys out of source code. Use environment variables or a secrets manager, and don’t commit them to GitHub.
GROUP 9: SCHEDULING, ASYNC AND MISC
Annotation | What it does |
|---|---|
| Runs a method on a schedule |
| Runs a method in a separate thread |
| Caches method results |
| Creates a |
| Generates boilerplate code |
java
Remember to add @EnableScheduling on a configuration or main class.
GROUP 10: TESTING
Annotation | What it does |
|---|---|
| Loads the full application context for an integration test |
| Tests only the web layer |
| Tests only the JPA layer with an in-memory database |
| Replaces a bean with a mock (newer Spring Boot versions prefer |
| Marks a JUnit test method |
| Runs before every test |
java
A COMPLETE MINI EXAMPLE: HOW THE ANNOTATIONS WORK TOGETHER
CHEAT SHEET: 40 SPRING BOOT ANNOTATIONS IN ONE TABLE
# | Annotation | Layer | One-line meaning |
|---|---|---|---|
1 |
| Setup | Main class: config + auto-config + scan |
2 |
| Setup | Auto-configure from dependencies |
3 |
| Setup | Where to look for components |
4 |
| Setup | Class that defines beans |
5 |
| Setup | Method that creates a bean |
6 |
| Stereotype | Generic managed class |
7 |
| Stereotype | Business logic class |
8 |
| Stereotype | Data access class |
9 |
| Web | MVC controller (views) |
10 |
| Web | REST controller (JSON) |
11 |
| DI | Inject a dependency |
12 |
| DI | Pick a specific bean |
13 |
| DI | Default bean |
14 |
| DI | Create when needed |
15 |
| DI | Bean scope |
16 |
| Lifecycle | Run after initialisation |
17 |
| Web | Map a URL |
18 |
| Web | Handle GET |
19 |
| Web | Handle POST |
20 |
| Web | Handle PUT |
21 |
| Web | Handle DELETE |
22 |
| Web | Value from the path |
23 |
| Web | Query parameter |
24 |
| Web | JSON body to object |
25 |
| Web | Set HTTP status |
26 |
| Web | Allow cross-origin calls |
27 |
| Exceptions | Global error handling |
28 |
| Exceptions | Handle a specific exception |
29 |
| JPA | Class maps to a table |
30 |
| JPA | Primary key |
31 |
| JPA | Auto-generated key |
32 |
| JPA | Column settings |
33 |
| JPA | Relationships |
34 |
| JPA | Custom query |
35 |
| Transaction | Commit or rollback as one unit |
36 |
| Validation | Trigger validation |
37 |
| Validation | Text must not be blank |
38 |
| Config | Inject a property |
39 |
| Config | Environment-specific bean |
40 |
| Testing | Full integration test |
ANNOTATION INTERVIEW QUESTIONS FOR FRESHERS
Question | Short answer |
|---|---|
What is | A convenience annotation combining |
| All register beans. |
|
|
What does | Tells Spring to inject a matching bean. Constructor injection is preferred. |
What if two beans match? | Use |
| Path value ( |
What does | Converts the request JSON into a Java object. |
What is | Runs a method in a transaction that commits on success and rolls back on failure (by default for runtime exceptions). |
Why might | Self-invocation within the same class, private methods, or a bean not managed by Spring. |
|
|
What is | A class that handles exceptions globally for all controllers. |
What is |
|
What does | Maps a class to a database table through JPA. |
What is auto-configuration? | Spring Boot configures beans automatically based on libraries on the classpath. |
How do you read a property value? |
|
COMMON MISTAKES FRESHERS MAKE WITH SPRING BOOT ANNOTATIONS
Mistake | Result | Fix |
|---|---|---|
Main class in a different package from the code | Beans not found | Keep it in the root package |
Forgetting | 404 or whitelabel page | Add the annotation |
Forgetting | Fields are null | Add |
Forgetting | Validation never runs | Add |
Using | Hard to test | Use constructor injection |
Calling a | No transaction | Move it to another bean |
Putting business logic in controllers | Messy code | Keep controllers thin |
Missing | JPA startup errors | Add both |
Committing passwords in properties | Security risk | Use environment variables |
Memorising names without understanding | Fails follow-ups | Explain with the request flow |
14-DAY SPRING BOOT ANNOTATIONS PLAN
Day | Focus | Task |
|---|---|---|
1 | Setup | Create a project, understand |
2 | Stereotypes | Build a controller, service and repository |
3 | Dependency injection | Practise constructor injection, |
4 | REST mappings | Write GET, POST, PUT and DELETE endpoints |
5 | Request data | Practise |
6 | JPA basics | Create an entity and a |
7 | Relationships | Add a |
8 | Validation | Add |
9 | Exception handling | Build a |
10 | Transactions | Write a |
11 | Properties and profiles | Use |
12 | Testing | Write a |
13 | Interview practice | Answer the table above aloud |
14 | Mini project | Combine everything in a small CRUD API with a README |
MYTH VS REALITY
Myth | Reality |
|---|---|
“There are hundreds of annotations I must memorise.” | About 40 cover most fresher projects and interviews. |
“ | Constructor injection is the recommended style. |
“ | It mainly documents the role. The bean creation comes from |
“ | It depends on proxies, so call patterns matter. |
“Annotations replace understanding.” | Interviewers ask why and how, not just what. |
“Lombok is mandatory.” | It’s optional. Know what it generates. |
HOW VIBRANTMINDS HELPS FRESHERS MASTER SPRING BOOT
VibrantMinds Technologies Pvt. Ltd. is a Pune-based IT training and placement support company. If you searched for VibrantMinds or VibrantMinds Technologies, here is what it offers:
Full Stack Java Development (about 4 to 6 months): Core Java, OOP, JDBC, SQL, Spring Boot, REST APIs, front-end basics, projects, aptitude and interview preparation. Please check the candidate portal for the latest syllabus and tools.
Software Testing (Manual + Automation), Core Java and Python & Data Science for other career paths
Project practice: Build Spring Boot projects you can host on GitHub and explain confidently
Interview preparation: Technical rounds, project rounds, HR rounds, aptitude, communication and mock interviews
Placement support: Screening, drive coordination and interview support. Check https://candidates.vibrantminds.in/ for current openings.
Free WhatsApp job alert groups for fresher IT jobs, campus drives and walk-in alerts
Honesty first: VibrantMinds offers placement support, not a guaranteed job, and no legitimate recruiter should ask you to pay to be interviewed.
VibrantMinds works as a talent ecosystem connecting candidates, colleges and companies, with 1900+ partner colleges and 600+ hiring companies. More fresher job guidance: https://candidates.vibrantminds.in/blog/fresher-jobs-pune-2026
VIBRANTMINDS COURSES AT A GLANCE
Course | Duration | Key topics |
|---|---|---|
Full Stack Java Development | 4 to 6 months | Core Java, OOP, JDBC, SQL, Spring Boot, REST APIs, front-end basics, projects, aptitude and interview preparation |
Software Testing (Manual + Automation) | 2 to 5 months | Test cases, STLC, bug tracking, SQL, Selenium basics |
Core Java | 1 to 2 months | Syntax, OOP, collections, exceptions, strings |
Python & Data Science | 2 to 4 months | Python basics, data handling, analysis fundamentals |
Fees, syllabus and batch dates are on https://candidates.vibrantminds.in/. Please confirm them directly before enrolling.
THE VIBRANTMINDS PLACEMENT PIPELINE: SIX STEPS
REAL OUTCOMES: WHAT TO EXPECT AND WHAT NOT TO
Past students have shared positive feedback about the training and support, and have gone on to roles at companies such as Aress Software and Education Technologies, Saama Technologies and Three M Software. Results vary by candidate, skill level, effort and market conditions, so please confirm details directly with the VibrantMinds team. No one can honestly promise a guaranteed job.
JOIN FREE VIBRANTMINDS WHATSAPP GROUPS: FREE IT JOB UPDATES FOR JAVA FRESHERS IN PUNE AND INDIA
Looking for free WhatsApp groups, free IT job WhatsApp groups, a Java WhatsApp group for freshers or a job updates WhatsApp group in India? The VibrantMinds groups share fresher IT openings, campus drives, walk-in interview alerts and interview preparation updates, free of charge. Join whichever group has space. All three carry the same type of updates.
Group | What it offers | Link |
|---|---|---|
VibrantMinds Fresher IT Jobs, Group 1 | Fresher openings, campus drives, walk-in alerts | |
VibrantMinds Fresher IT Jobs, Group 2 | Fresher openings, campus drives, walk-in alerts | |
VibrantMinds Fresher IT Jobs, Group 3 | Fresher openings, campus drives, walk-in alerts |
Never pay to apply. Legitimate recruiters do not charge candidates for tests, interviews or offer letters. Do not share sensitive personal or financial details in any group chat.
FREQUENTLY ASKED QUESTIONS
1. What are the most important Spring Boot annotations for freshers?@SpringBootApplication, @RestController, @Service, @Repository, @Autowired (or constructor injection), @GetMapping, @PostMapping, @PathVariable, @RequestParam, @RequestBody, @Entity, @Id, @Transactional, @Valid, @Value and @SpringBootTest. Learn them by layer using the cheat sheet above.
2. What is the difference between @Component, @Service and @Repository?
All three register a class as a Spring bean. @Component is generic, @Service marks business logic and @Repository marks data access and also translates persistence exceptions into Spring’s exception hierarchy. Use the most specific one so the role of each class is clear.
3. How does @Transactional work in Spring Boot for beginners?
It wraps a method in a database transaction through a proxy: if the method completes normally the changes are committed, and if a runtime exception occurs they are rolled back. It can fail to apply when you call the method from within the same class, use a private method or the class isn’t a Spring bean.
4. How do I use @Valid and @NotBlank for validation in Spring Boot?
Add the validation starter, put constraints such as @NotBlank, @Email and @Min on your request class fields, and add @Valid before @RequestBody in the controller. Invalid input throws MethodArgumentNotValidException, which you can convert into a clean 400 response with @RestControllerAdvice.
5. Is there a free WhatsApp group for Java freshers in Pune?
Yes. VibrantMinds runs free fresher IT job WhatsApp groups that share Java and other IT openings, campus drives and walk-in alerts. Join through the links above, and always verify a job post and never pay to apply.
CONCLUSION: LEARN SPRING BOOT ANNOTATIONS BY LAYER
The easiest way to master Spring Boot annotations is to stop memorising a long list and learn them by layer: setup, web, service, data, validation and testing. Build a small CRUD API, add each annotation when you need it, explain the request flow aloud and use the cheat sheet and 14-day plan to revise. Prefer constructor injection, understand how @Transactional really works and keep your controllers thin.
If you’re in Pune and want structured Java and Spring Boot training with real project practice, interview preparation and placement support, VibrantMinds Technologies is here to help.
Call to action:
Website: https://vibrantminds.in/
Candidate portal and courses: https://candidates.vibrantminds.in/
Fresher jobs guide: https://candidates.vibrantminds.in/blog/fresher-jobs-pune-2026
Join the free WhatsApp groups: the three links above
VISIT OR CONTACT VIBRANTMINDS IN PUNE
Company: VibrantMinds Technologies Pvt. Ltd.
Address: Viva Academy Building, Warje, Pune, Maharashtra 411052
Phone: +91 95035 79517
Email: support@vibrantmindstech.com
Website: https://vibrantminds.in/
Candidate portal and courses: https://candidates.vibrantminds.in/


