Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

Adobe Summit 2023 [19th to 23rd March, Las Vegas and Virtual] | Complete AEM Session & Lab list

Custom Java AEM annotation to do validations.


Level 1

Hi everyone,


I created a custom annotation that I would like when a method annotated with it is called, it automatically calls a service also created by me.

My Servlet

public void doPost(@Nonnull SlingHttpServletRequest request, @Nonnull SlingHttpServletResponse response) throws ServletException, IOException {


My Annotation

public @interface MyValidator {


My Service

public class ValidatorServiceImpl implements RecaptchaValidateService {

//I will need to inject other services like other AEM service
private HttpRequestService requestService;

public void validate() {
...get first the SlingHttpServletRequest and then validate the request
if (isNotValid) throw new RuntimeException("my message")

The idea is to make a validation annotation. But I don't know how to add a listener for this annotation in OSGi.

Do you have any idea how I can do it?

1 Reply