Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8935499
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T09:59:45+00:00 2026-06-15T09:59:45+00:00

How do we configure annotation based spring aspect in java? Lets say we want

  • 0

How do we configure annotation based spring aspect in java?

Lets say we want to intercept a spring service, we usually do it by AOP pointcut expression. This example details how to do it using annotation instead of expression. This is more portable as we use annotation.

There are many examples but very few have the right content. Hence putting it here…

This is a solved question. I am posting my answer so it helps others including myself..

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T09:59:47+00:00Added an answer on June 15, 2026 at 9:59 am

    Annotation based AOP advice in spring

    1.define annotation

     public @interface ApplyAuthorisationAdvice {
     }
    

    Set <aop:aspectj-autoproxy /> in spring config file if not done before

    2.

    import org.aopalliance.aop.Advice;
    import org.aspectj.lang.annotation.Aspect;
    
    @Aspect
    @Component
    public class AuthorisationAspect implements Advice {
    
        private final static Logger logger = Logger.getLogger(AuthorisationAspect.class);
    
        @Autowired
        MyService myService;
    
        @SuppressWarnings("unchecked")
        @AfterReturning(pointcut = "@annotation(com.example.ApplyAuthorisationAdvice)", returning = "result")
        public void afterReturning(JoinPoint joinPoint, Object result) {
    
            if (result != null && (result instanceof List)) {
                // filter stuff
            }
    
        }
    }
    

    3.Apply annotation on service which needs to be intercepted

    @Component("myService")
    public class MyServiceImpl implements MyService {
      @ApplyAuthorisationAdvice 
       public List<MySummary> search(MyContext searchContext) {
       }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to configure a class with Annotation based configuration in Spring 3, which
I'm investigating an annotation-based approach to validating Spring beans using spring modules . In
When using spring @Transcational on service layer, I will need to put <annotation driven>
I'm developing bunch of relatively small Spring based java web-application. I'm mostly using annotations
I'm using Hibernate for a Java-based Web Application and want to add full-text search
I configure eclipse Helios Service Release 2 , eclipse properly download and configure ADT
I have a class and i want to annotate it as a service. What
I am displaying different annotation points in a mapview. I want to display different
I want to understand form based security and JDBC realms with glassfishV3, so i
Background: I have a Spring 2.5/Java/Tomcat application. There is the following bean, which is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.