Solved

Spring, Servlet web project Integration approaches

Posted on 2011-09-08
1
261 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
xampp tool 12 51
hibernate example using maven 12 42
How do I remove an object from a 3 27
difference between sorce folder and folder in eclipise 3 14
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
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…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

809 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