0
0
Spring Bootframework~5 mins

@Aspect annotation in Spring Boot - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the purpose of the @Aspect annotation in Spring Boot?
The <code>@Aspect</code> annotation marks a class as an aspect, which contains cross-cutting concerns like logging or security that can be applied across multiple parts of an application.
Click to reveal answer
intermediate
How does an <code>@Aspect</code> class interact with other parts of the application?
An <code>@Aspect</code> class defines advice (code to run) and pointcuts (where to run it). Spring uses these to weave the advice into the application at specified join points like method calls.
Click to reveal answer
beginner
Which Spring Boot module must be included to use @Aspect?
You need to include spring-boot-starter-aop in your project dependencies to enable Aspect-Oriented Programming features like @Aspect.
Click to reveal answer
intermediate
Can an <code>@Aspect</code> class have state (fields) that change during execution?
It's best to keep @Aspect classes stateless or thread-safe because Spring may create a single instance shared across threads.
Click to reveal answer
beginner
What is a common real-life example of using @Aspect in an application?
Logging method execution time is a common use. An @Aspect can measure how long methods take and log this info without changing the method code itself.
Click to reveal answer
What does the @Aspect annotation do in Spring Boot?
AMarks a class as containing cross-cutting logic
BDefines a REST controller
CMarks a class as a database entity
DEnables caching for a method
Which dependency is needed to use @Aspect in Spring Boot?
Aspring-boot-starter-aop
Bspring-boot-starter-data-jpa
Cspring-boot-starter-web
Dspring-boot-starter-security
What is a 'pointcut' in the context of an @Aspect?
AA method that runs advice
BA type of exception
CA place where advice is applied
DA database query
Which advice type runs before a method execution in an @Aspect?
A@After
B@Before
C@Around
D@AfterReturning
Why should @Aspect classes be stateless or thread-safe?
ABecause Spring creates multiple instances
BBecause aspects cannot have fields
CBecause aspects run only once
DBecause Spring shares a single instance across threads
Explain what the @Aspect annotation does and how it helps in a Spring Boot application.
Think about how you can add logging or security checks without changing every method.
You got /4 concepts.
    Describe the relationship between an @Aspect class, advice, and pointcuts.
    Consider how the aspect knows when and where to run extra code.
    You got /4 concepts.