1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package edu.sampleu.travel.infrastructure;
17
18 import java.io.FileNotFoundException;
19
20 import javax.servlet.ServletContextEvent;
21 import javax.servlet.ServletContextListener;
22
23 import org.apache.log4j.Logger;
24 import org.springframework.util.Log4jConfigurer;
25
26
27
28
29
30
31
32
33 public class TravelAppInitializeListener implements ServletContextListener {
34 private static final Logger LOG = Logger.getLogger(TravelAppInitializeListener.class);
35
36 public void contextDestroyed(ServletContextEvent sce) {
37
38 }
39
40 public void contextInitialized(ServletContextEvent sce) {
41 try {
42 Log4jConfigurer.initLogging("classpath:log4j.properties");
43 } catch (FileNotFoundException e) {
44 throw new RuntimeException("Failed to start sample application.", e);
45 }
46
47 Object o = sce.getServletContext().getAttribute("JETTYSERVER_TESTMODE");
48 boolean testMode = false;
49 if (o != null) {
50 testMode = Boolean.valueOf((String) o);
51 }
52 LOG.info("Travel webapp starting up in " + (testMode ? "test" : "normal") + " mode");
53
54 TravelServiceLocator.initialize(testMode);
55 }
56 }