1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package net.sourceforge.statelessfilter.spring;
17
18 import javax.servlet.ServletContext;
19
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
22 import org.springframework.context.ApplicationContext;
23 import org.springframework.web.context.support.WebApplicationContextUtils;
24
25
26
27
28
29
30
31 public class SpringContextChecker {
32 private static Logger log = LoggerFactory
33 .getLogger(SpringContextChecker.class);
34
35
36
37
38
39
40
41 public static boolean checkForSpring(ServletContext context) {
42 try {
43 Class<?> contextUtils = Class
44 .forName("org.springframework.web.context.support.WebApplicationContextUtils");
45
46 if (contextUtils != null) {
47 ApplicationContext appContext = WebApplicationContextUtils
48 .getRequiredWebApplicationContext(context);
49 if (appContext != null) {
50 if (log.isInfoEnabled()) {
51 log
52 .info("Spring is available AND an application context has been found.");
53 }
54 return true;
55 }
56 }
57
58 return true;
59 } catch (Exception e) {
60 if (log.isInfoEnabled()) {
61 log.info("Spring is not available.");
62 }
63 }
64 return false;
65 }
66
67 }