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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T13:08:01+00:00 2026-06-17T13:08:01+00:00

I am learning spring aop now,and I have no idea to pass context arguments

  • 0

I am learning spring aop now,and I have no idea to pass context arguments to the advice.

Note I mean the context arguments,not the normal arguments.

It is simple to pass the normal arguments,for example:

a join point:
public void read(String something){

}

@Aspect
public class SessionAspect {
    @Pointcut("execution(* *.*(String)) &&args(something)")
    public void sess() {
    }

    @Before("sess()")
    public void checkSessionExist(String something) {
        //Here
    }
}

Then the something argument will be passed to the the advice checkSessionExist.

But how about I want to get the context arguments like HttpSession or something else?

a join point:

public void listUser(){
    dao.list(User.class,.....);
}

@Aspect
public class SessionAspect {
    @Pointcut("execution(* *.*(String))")
    public void sess() {
    }

    @Before("sess()")
    public void checkSessionExist(String something) {
        //Here
    }
}

In this example,the listUser join point is only allowed for logined user.

So I want to check if there is a identify in the current HttpSession,so I need to get an instance of HttpSession at the advice checkSessionExist.

But how to get it?

The simplest way is to add the HttpSession argumets to all the joit points like this:

public void listUser(HttpSession session){
    dao.list(User.class,.....);
}

However this have gone against the AOP it self. In my opinion,the join point even does not need to know the exist of the Aspect,isn’t it?

How to fix it ?

  • 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-17T13:08:02+00:00Added an answer on June 17, 2026 at 1:08 pm

    Instead of passing HttpSession via @Pointcuts, you could fetch HttpSession reference in the @Aspect itself

    RequestContextHolder.currentRequestAttributes()
    .getAttribute("user", RequestAttributes.SCOPE_SESSION)
    
    @Aspect
    public class SessionAspect {
    
        // fetch the current HttpSession attributes and use as required 
        private ServletRequestAttributes attr = (ServletRequestAttributes) RequestContextHolder.currentRequestAttributes();
    
    
        @Pointcut("execution(* *.*(String))")
        public void sess() {
        }
    
        @Before("sess()")
        public void checkSessionExist(String something) {
            //Here
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am learning spring-mvc and I am doing a simple crud. I have a
I`m still in a learning stage with spring transactions and aop, and i have
I am learning Spring 3.x MVC. I now have a regular web page setup
I am learning spring mvc and hibernate. i have just finished simple site with
I'm learning spring dependency injection. I have 2 types of code. One works and
I am learning Spring and writing a simple program to inject a property into
I am learning Spring and I have a question regarding how you use it
I am learning Spring and I have a question regarding the preInstantiateSingletons method on
I have been learning java spring hibernate MVC for 3 months and got pretty
I was learning how to make simple form validation using this tutorial: http://www.raistudies.com/spring/spring-mvc/form-validation-spring-mvc-3-hibernate-validator-jsr-303/ The

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.