Solved

Spring, Servlet web project Integration approaches

Posted on 2011-09-08
1
262 Views
Last Modified: 2012-05-12

i was reading about
Spring, Servlet web project Integration approaches
Approach 1:
         Create web project then add spring capablities by making sure applicationContext.xml file is in WEB-INF folder. Then Create servlet program. Configure dao to access the database.Introduce spring container by Creating singleton class of ApplicationContext as it should be started only once as all beans should be available to servlets.

Approach 2:
ServletContext object is created per application as a singleton object.When ServletContext object is created, listeners are invoked.
 configure Spring container which is started when  application is started which depends on your ServletContext listener by Saving instance of ApplicationContext in ServletContext object as attribute
          I would liek to know which approach is better which one we use where, advantages, disadvantages of each one. I was not clear on this concept. thanks in advance
0
Comment
Question by:gudii9
1 Comment
 
LVL 21

Accepted Solution

by:
Amitkumar Panchal earned 500 total points
ID: 36929928
Hi,

Follow the Approach 2. Refer the section 15.2 Common configurations in http://static.springsource.org/spring/docs/2.5.x/reference/web-integration.html

Comments regarding Approach 1:

- you should have this single servlet
- it should be stateless except for the context
- you should have only one instances of this servlet (specifiable in the web.xml)
- you might have integration problems with other parts of the Spring infrastructure or with examples which relies on the application context maintained in a particular place in the servlet context AND that they expect the application context to be of the type org.springframework.web.context.WebApplicationContext
- You need to close the application context in the destroy method of the servlet.
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Apps blocked by Java 9 88
varialbe initialization 11 37
MySQL  on Tomcat 8 68
Delete Android all or certain applications data programmatically 9 68
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question