I have always loved Spring for its extensibility. Since it provides so many links for customizations via callback interfaces and via declarative configuration, it's really easy to hook it up to custom frameworks.
However, I have been fighting with Spring all day to get the following done. Imaging a bean like this:
This bean serves web requests. For every request, I want it to execute the init() method before actually starting to handle the request.
public class someBean()
public void init()
// my framework stuff goes here
With request scope it is easy. You can use the default Spring way, using the init-method attribute. So far so good.
But now I am trying to get this done with session scoped beans. Some things I've tried - not all that nice, but you know how it feels when you're running out of inspiration ...
1. BeanPostProcessor: having my beans extend this marker interface would not work because then they are "lazy-init=false" by default, resulting in IllegalStateExceptions at startup because they are created outside the scope of a valid request (and thus session) scope. Anyway, I fear this would not have led me far anyway, because it would not be executed for every request.
2. Ugly: defining a custom scope and have my custom scope class call the init() method. To avoid duplicate init() calls for one request my bean stores a reference to the request object, and checks if it had already run init() for the request. Unfortunately for some reason this fails too. I don't want to waste more time investigating whey, before I know there really is no better way.
So here's my question: does someone know how to make Spring call a method on a bean with session scope once for every request?
I have searched the forum already and googled around for hours. And so I would be very greatful if someone could help me out of this dead end street !!