import javax.servlet.ServletContextListener;
import javax.servlet.ServletContextEvent;
import org.apache.log4j.Logger;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
/**A quick and easy way to get access to the Spring context from anywhere in the application.
*/
public class SpringContext
implements ServletContextListener {
private static final Loggerlogger = Logger.getLogger(SpringContext.class);
private static ApplicationContext context;
private static String errorMessage;
public static ApplicationContext getContext()
{
if ((context == null) && (SpringContext.errorMessage != null)) {
throw new RuntimeException(SpringContext.errorMessage);
}
return context;
}
public void contextInitialized(ServletContextEvent arg0) {
try {
logger.debug("SpringContext::Starting Spring configuration.");
String appContextPathName = "applicationContext.xml";
context = new ClassPathXmlApplicationContext(appContextPathName);
} catch (Exception x) {
logger.error("Error loading Spring Context " + x.getMessage(), x);
SpringContext.errorMessage = x.getMessage();
}
}
public void contextDestroyed(ServletContextEvent arg0) { }
}
Try to use a "kickstarting" application like AppFuse (http://raibledesigns.com/wiki/Wiki.jsp?page=AppFuse). This application has all
pre-configured parts of good web-application, check it out. There are some options of web-frameworks, and Spring MVC amongst them. So, you can learn how to configure Spring and use it.