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 8204899
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T08:02:28+00:00 2026-06-07T08:02:28+00:00

I have a class that is using Spring AOP framework in my web app

  • 0

I have a class that is using Spring AOP framework in my web app just like the code shown below. I was wondering why the Spring AOP was able to trace add() but not able trace multiple() if I implement the following code.

public interface calculator {
   public void add();
   public void multiple();
}

public class calculatorImpl implements calculator {

   public void add() {

      multiple();
   }

   public void multiple() {}
}

I’ve did an experiment and found out that the following code is working fine. Meaning that the Spring AOP able to trace both add and multiple function.

ICalculator calcProxy = (ICalculator) context.getBean("calculatorProxy");
calcProxy.add();
calcProxy.multiple();

I think that must be cause by the multiple() was inject by the proxy bean whereas the multiple() in calculatorImpl class wasn’t, thus Spring AOP wasn’t able to trace it. Correct me if I am wrong.

My next question. Is there a work around on this issue where the add() really need to execute multiple() and get trace by the Spring AOP?

  • 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-07T08:02:31+00:00Added an answer on June 7, 2026 at 8:02 am

    Spring AOP doesn’t change the actual method, but adds a proxy around the Object. Once you are inside the inner Object (inside the add() method), there is no proxy, you are underneath it.

    I have explained this mechanism in more detail in this past answer:

    https://stackoverflow.com/a/4171649/342852

    There are three ways to deal with that situation:

    1. Use AspectJ, not Spring AOP. AspectJ compiles the behavior into your code, whereas Spring AOP works with proxies that surround your code.
    2. Access the Proxy from inside the Bean. This is reeeeaaally ugly, but it can be done.
      Example code (here you make the class aware of it’s being proxied, which is contrary to everything AOP stands for):

      public void add() {
         ((Calculator)AopContext.currentProxy()).multiple();
      }
      

      Slightly less horrible (here you make the class aware that it’s being managed by Spring):

      @Autowired
      private ApplicationContext context;
      public void add() {
         context.getBean(Calculator.class).multiple();
      }
      
    3. Change your design. Example: move the two methods to separate beans and inject each into the other bean.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class that I am using below. And I am using this
In my Spring context file I have something like this: <bean id=userCheck class=a.b.c.UserExistsCheck/> <aop:config>
I'm using Spring 3.0.2 and I have a class called MovieDAO that uses JDBC
I have an application that is already using the Spring Framework and Spring JDBC
I am using spring 3 mvc/security frameworks. I have created a Controller class that
Using: Spring 3.1.0.RELEASE, Spring Data MongoDB 1.0.0.RELEASE I have a document class defined like
I am using Spring 3 AOP, and I have an aspect that requires access
I'm developing a web-app and I'm using Spring framework. Thing is, i never properly
I have a Web app using Spring 3.1.1 and Spring Security 3.1.0. I implemented
I have a class that is mapped to a table using NHibernate. The problem

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.