3

I'm new to spring and I've written a method that uses the HttpSession object. I use the method qite often. Right now I pass the parameter as a argument to the method. But that means that everywhere I use the method, I need to pass it in as a parameter, which means the method calling it needs the parameter HttpSession as parameter. I was wondering if I could somehow pass the session automatically (@Autowire?) so I dont need to pass it every time I use the method:

As an example:

public User getUser(HttpSession session){
   //DoStuff
}

Everywhere I call the method I need to pass in the session:

public void addItem(@RequestParam(value="id") int id, HttpSession session){
        super.getUser(session);
       //doStuff
}

I don't want the HttpSession session in the signature, whenever I have to call getUser(...), Is there a way to let Spring fill in this session in getUser(), automatically?

1 Answer 1

4

Try using:

@Autowired 
private HttpSession httpSession;
Sign up to request clarification or add additional context in comments.

1 Comment

Great, thank you, I'm feeling so stupid right now :s

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.