May 11th, 2010, 10:55 AM
Application Context Best Uses
We are developing a web based application with presentation, business and data layers.
Now, we get the ApplicationContext reference (from SevletContext) in presentation layer which we can use to get reference of “beans”.
Now my queries are:
1) If I need to get a bean reference in business layer, how to do this.
2) Is it a good idea to pass reference of ApplicationContext to business layer
Any suggestion is welcome.
Thanks in advance.
May 11th, 2010, 01:30 PM
THe best best practice is to not directly use the BeanFactory/ApplicationContext. You should simply use dependency injection and avoid dependency lookups. It makes your application also a lot simpler and also not dependend on spring.
May 12th, 2010, 04:27 AM
Thanks Marten for the response.
I am really not sure how to inject ApplicationContext. Can you please elaborate a bit more on this.
Thanks & Rest Regards,
May 12th, 2010, 04:41 AM
As stated you shouldn't inject the ApplicationContext, you shouldnlt be using that directly. No matter if you do injection or not. YOu should simply inject those dependencies needed (daos, services etc).
May 12th, 2010, 08:08 AM
Thanks a lot Marten. I got your point.