• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Integration of Spring with a servlet

 
shanthi naidu
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you have the Spring JARs on the classpath?
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@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
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic