How to access a Spring bean from a Servlet

Here is a reference:

http://javageek.org/2005/09/23/accessing_a_spring_bean_from_a_servlet.html

In summary:

Basically, you use the WebApplicationContextUtils object from the spring framework to get a reference to your bean. Inside the doGet() method I have:

ApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(getServletContext());
Object myDao = context.getBean("daoBeanName");


Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s