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

  • SEARCH
  • Home
  • 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 6564893
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:01:34+00:00 2026-05-25T14:01:34+00:00

I am in the process of adding some AspectJ advices in my Spring -based

  • 0

I am in the process of adding some AspectJ advices in my Spring-based Java project. When I run an intercepted method once, it all works fine (i.e., the advice is executed). However, the next invocation of the very same method does not go through the proxy anymore.

This is my test code:

@Test
public void testFooOperationIsAdviced() throws Exception {
    TestController testController = appContext.getBean("testController");
    testController.foo();
    testController.foo();
}

Here’s the foo() method:

@Protect()
public void foo() {
    System.err.println("foo!")
}

And this is the relevant part in my Spring configuration:

<aop:aspectj-autoproxy />
<bean name="myAdvice" class="mypackage.MyAdvice"/>

<bean id="testController" class="mypackage.MyTestControllerImpl" />

<aop:config>
    <aop:aspect id="protectAspect" ref="myAdvice">
        <aop:pointcut id="annotatedController" expression="execution(public * mypackage.*+.*(..)) and @annotation(protect)" />
        <aop:around pointcut-ref="annotatedController" method="applyProtectionRules" arg-names="protect"/>
    </aop:aspect>
</aop:config>

The aspect is currently just doing System.err.println("advice") and pp.proceed().

So, if we execute the test above, you’d expect

advice
foo!
advice
foo!

However, what I get is:

advice
foo!

The second invocation never gets to the advice! And, what is worse, the target method is not even executed.

Do you have any clue as to why this happens?

Note 1: To make things worse: sometimes, when I execute with the debugger and go step by step, it does work normally. No kidding…

Note 2: If there are typos in the config, they are just typos, since I adapted the original code to make it simpler. Take into account that the aspect does work for the first invocation.

Note 3: I do want to stick to Spring. I can’t have the pointcuts hardcoded in the Java code, since I want the library user to provide their own, and the only way I can think of is let them define the aop:config block.

  • 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-05-25T14:01:34+00:00Added an answer on May 25, 2026 at 2:01 pm

    Looking at the 2-kilometer-long stack trace, I saw a CachingInterceptor… That’s the solution to the mystery: our custom caching mechanism, based on a Spring method interceptor, was doing the trick. It has a timeout of 120 seconds, and that’s why the execution seemed fine when I used the debugger.

    I won’t close my (admittedly dumb) question in case it helps others. A bit of perspective and thinking out of the box would’ve helped!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm in the process of adding some UI functionality to a hybrid WebForms/MVC site.
I'm in the process of adding some much needed client side form validation to
I am in the process of adding some lines of code to change the
I have a Delphi 2006 app that I am adding code to process some
i have one php file which process adding of record in Database fro array.
I'm in the process of adding custom buttons to my iPhone UI and want
I'm in the process of adding CAPTCHA validation to one of my websites and
I'm in the process of adding a Data Access Layer for our ASP.Net 2.0
I'm currently in the process of adding JNI functionality into a legacy delphi app.
Is there anyway I can make the process of adding references to C# projects

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.