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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T12:56:40+00:00 2026-06-01T12:56:40+00:00

Please consider the following: we have a Spring bean B which is advised with

  • 0

Please consider the following: we have a Spring bean B which is advised with a number of aspects: A1, A2. We have some other Spring beans: X, Y, Z — and B is injected to all of them. The question is: how can we make aspects of B to be applied or not depending on bean from which B is invoked (X, Y, Z)? In my particular task I need to make one aspect (for example, A2) to be bypassed when B is invoked from particular bean (for example, Z), while in other invocations all aspects must be applied.

  • 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-01T12:56:42+00:00Added an answer on June 1, 2026 at 12:56 pm

    The decision was quite simple. Z contains the reference to B, and this reference is of type Advised. This interface allows accessing different properties of advised object, including its aspects. This allows creating new advised object which includes only needed aspects of B. The code snippet follows.

    All types and identifiers are given in respect to example from the original question. B is ab interface, b is a reference. Code snippet is from Z bean.

    Class<?>[] classes = {B.class};
    AdvisedSupport config = new AdvisedSupport(classes);
    try {
        config.setTargetSource(((Advised) b).getTargetSource());
    } catch (Exception e) {
        e.printStackTrace();
    }
    for (Advisor advisor : ((Advised) b).getAdvisors()) {
        Advice advice = advisor.getAdvice();
        if ((advice instanceof AbstractAspectJAdvice) && "advice.A2".equals(
                ((AbstractAspectJAdvice) advice).getAspectName())) {
            // Do not add A2 advisor
        } else {
            config.addAdvisor(advisor);
        }
    }
    DefaultAopProxyFactory factory = new DefaultAopProxyFactory();
    B newB = (B)factory.createAopProxy(config).getProxy();
    

    Now newB reference is ready for use.

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

Sidebar

Related Questions

Please consider the following three .NET types: I have an interface, an abstract class,
Please consider the following: <td style=width: 500px;> <div style=width: 400px;>SomeContent</div> </td> For some reason,
Please consider the following: http://jsfiddle.net/CASM6/9/ I have two rows of tabs. there are two
please consider the following: I have a queue of objects represented as an array.
I have a issue with one of my spans. Please consider the following styles:
I have an app that's about presenting fictional simplified cities. Please consider the following
Please consider the following Amount value type property which is marked as a nullable
Please consider the following table structure on Oracle: create table DOCS ( DOC_NO NUMBER
I'm writing some Boost.Preprocessor metaprogram, and I have the following problem. Consider the following
Please consider the following scenario. I have a form with a property: class MyForm

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.