Koraktor
Koraktor

Reputation: 42983

Calling @Controller methods once per request

Is there a nice way to have Spring's @Controller classes to call a specific method once per request?

Right now I'm using a method annotated with @InitBinder for this purpose, but this is suboptimal as @InitBinder methods get called several times per request. I just want to do some initialization / update stuff to use in my controllers.

What I'm looking for is something like Rails' before_filter, but as far as I can tell there's no functionality like that in Spring.

Upvotes: 0

Views: 2439

Answers (1)

skaffman
skaffman

Reputation: 403611

Sounds like you need a request-scoped controller bean. Spring will create a new instance of the controller for each request, and will initialize the bean each time using the standard mechanisms like @PostConstruct.

Upvotes: 1

Related Questions