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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T22:21:58+00:00 2026-05-25T22:21:58+00:00

I am experimenting with Spring AOP for the first time and get stuck in

  • 0

I am experimenting with Spring AOP for the first time and get stuck in the XML configuration. I’m trying to get a mock version of AOP-based “logging” up and running, using a MethodInterceptor to wrap specific method calls and do some simple System.out.println statements before and after those method invocations. Simple stuff, right?

So my project has many classes, two of them are Fizz and Buzz. Fizz has a method named foo() and Buzz has a method named wapap(). Every time these methods are invoked at runtime, I want my LoggingInterceptor to execute its invoke() method around them:

public class LoggingInterceptor implements MethodInterceptor
{
    public Object invoke(MethodInvocation methodInvocation)
    {
        try
        {
            System.out.println("About to call a special method.");
            Object result = methodInvocation.proceed();
            return result;
        }
        finally
        {
            System.out.println("Finished executing the special method.");
        }
    }
}

So I understand the concepts of advice (my interceptor impl), pointcuts (the methods that will have advice executed around them), and pointcut advisors (bindings between advice and pointcuts).

I’m just struggling tying it altogether in a simple XML config.

Here’s what I have so far, but I know it’s missing pointcut and pointcut advisor definitions, and possibly more.

<beans default-autowire="no" >
    <bean name="loggingInterceptor" class="org.me.myproject.aop.LoggingInterceptor"/>   
</beans>

What am I missing here to make this specific to Fizz::foo() and Buzz::wapap() calls?

Any nudges in the right direction are enormously appreciated!

  • 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-25T22:21:59+00:00Added an answer on May 25, 2026 at 10:21 pm

    Add this:

    <aop:config>
        <aop:advisor advice-ref="loggingInterceptor" pointcut="execution(public * Fizz.foo(..))"/>
        <aop:advisor advice-ref="loggingInterceptor" pointcut="execution(public * Buzz.wapap(..))"/>
    </aop:config>
    

    You also need to add AOP namespace declaration in version appropriate to your framework:

    <beans xmlns="http://www.springframework.org/schema/beans"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xmlns:aop="http://www.springframework.org/schema/aop"
           xsi:schemaLocation="
            http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
            http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
            ">
    

    Also consider using @AspectJ aspects and see this question: Spring: Standard Logging aspect (interceptor).

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

Sidebar

Related Questions

While experimenting with this question on collections in Spring.NET , I discovered that Spring
Experimenting with Scala... I'm trying to define something analogous to the @ hack in
I'm experimenting with the spring 3 MVC framework. Since i use maven 2 to
I have just started reading Spring In Action - Third edition and am stuck
I've been experimenting with difference between intrinsic locks and java.util.concurrent.ReentrantLock for some time now.
I'm currently experimenting with GWT and Spring. More specifically I wanted to make the
I'm experimenting some difficulties trying to use Connection String Builders (ADO.NET) within LINQ to
I've been experimenting with various bits of Java code trying to come up with
Im currently reading Spring in Action 3rd edition, and have been experimenting with Spring
I am trying to create a dynamic proxy using Spring.NET and C# for a

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.