0

I have a session scoped bean in my @Controller: it is called SessionPreferences and I hope its name will explain what it does :-)

Almost any of my controllers make use of it, so I easily inject it in each controller via @Autowired.

I wanna go deeper so.... how can I avoid this duplication? Can I have a "father" controller in my application, in order to store all shared references to services, other beans and so on?

1
  • What do you mean by "go deeper"? Commented Mar 9, 2012 at 15:17

1 Answer 1

1

Maybe an abstract class that the controllers implement would be helpful?

If I'm understanding you, though, you want a class that you basically inject all of your services and daos into directly then the rest of those classes would inherit off of it?

This might cause issues with the way Spring sets up it's proxies when classes reference the singletons you inject. Not 100% sure though, might want to avoid doing this.

Also, if you break one of your services, all of your controllers that inherit from that base class would be broken, don't really recommend this. You're coupling your controllers with too many facets of your application.

Sign up to request clarification or add additional context in comments.

3 Comments

@dardo: I simply need my SessionPreferencesKeeper bean to be available to ALL controllers. If you think that injecting it everywhere is better than use controller inheritance.... tell me :)
I think it would be better personally. That way you let spring handle the proxy on the singleton. If you inherit the inject from all your subclasses you MIGHT, and i do mean might lol, have issues with contention
ok thank you. All I need is to have access, in all controllers, to some default-standard objects. I solved (still trying...) with INTERCEPTORS.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.