my dog learned polymorphism*
The moose likes Spring and the fly likes Integration of Spring with a servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Integration of Spring with a servlet" Watch "Integration of Spring with a servlet" New topic
Author

Integration of Spring with a servlet

shanthi naidu
Ranch Hand

Joined: Nov 13, 2008
Posts: 39
Hi,

Im not using Spring MVC... but i have to initialize the Spring Contatiner in the servlet manually

I have written the below code to initialize the container in the servlet's doGet(-,-) method..



But im getting the NoClassDefinitionFound error for the ClassPathXmlApplicationContext
though i have imported the package import org.springframework.context.support.*;

What can i do to solve this problem?
can i initialize the container like this in the servlet??

Thanks,
Shanthi Naidu
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

Do you have the Spring JARs on the classpath?


-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

You really don't want to do this in a doGet--consider using a ContextLoaderListener and accessing the context in a different way.
shanthi naidu
Ranch Hand

Joined: Nov 13, 2008
Posts: 39
@Nathan

Im using Eclipse IDE so i have included all the jar files required


@David

but i want to access through servlet only
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

shanthi naidu wrote:@Nathan

Im using Eclipse IDE so i have included all the jar files required


@David

but i want to access through servlet only


There is a WebApplicationContextUtils class that you can call a method on to get the ApplicationContext. and from there you can call getBean(). You would put this code in the init method, so that the "service" is always available to the Servlet, instead of getting the bean for every client that is going through the doGet on every request.




Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

shanthi naidu wrote:but i want to access through servlet only

The context loader listener is how the context is initialized, not how it's accessed.
 
GeeCON Prague 2014
 
subject: Integration of Spring with a servlet