Back Forum Reply New

pass information from one aspect to another

Hi Guys,  I have typical requirement where I need to pass information from one aspect to another.
1, My first aspect will capture details in Action level. Here I will generate a unique id and saved in DB.
2, Second aspect will capture details in Service level of the same request. These details are child record of Action level details. When I insert service level details into DB I need Action level unique Id.

I have tried with Session. But request object will not available in service methods. How can I solve it?

Use a session-scoped bean to hold id information.
Inject that bean in beans of both aspects.
In the first aspect, set the id property in the session-scoped bean before returning.
In the second aspect, retrieve the id property from the bean.

If the controller and service are always serving the same from request, you better use a request-scoped bean instead of a session-scoped bean.

Thanks Enrico Pizzi. It works.
Is it possible get fromSession values from session scoped bean? Because I need username from session.

Also beware that if your Aspect beans are singletons, injecting request/session scoped dependencies into them requires wrapping those dependencies into AOP scoped proxies (preferably with lt;aop:scoped-proxy/gt;).
¥
Back Forum Reply New