|
18 | 18 |
|
19 | 19 | import javax.servlet.ServletException;
|
20 | 20 |
|
21 |
| -import org.eclipse.jetty.util.component.AbstractLifeCycle; |
22 | 21 | import org.eclipse.jetty.webapp.AbstractConfiguration;
|
23 | 22 | import org.eclipse.jetty.webapp.Configuration;
|
24 | 23 | import org.eclipse.jetty.webapp.WebAppContext;
|
@@ -49,54 +48,35 @@ public ServletContextInitializerConfiguration(
|
49 | 48 |
|
50 | 49 | @Override
|
51 | 50 | public void configure(WebAppContext context) throws Exception {
|
52 |
| - context.addBean(new Initializer(context), true); |
53 |
| - } |
54 |
| - |
55 |
| - /** |
56 |
| - * Jetty {@link AbstractLifeCycle} to call the {@link ServletContextInitializer |
57 |
| - * ServletContextInitializers}. |
58 |
| - */ |
59 |
| - private class Initializer extends AbstractLifeCycle { |
60 |
| - |
61 |
| - private final WebAppContext context; |
62 |
| - |
63 |
| - Initializer(WebAppContext context) { |
64 |
| - this.context = context; |
| 51 | + ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); |
| 52 | + Thread.currentThread().setContextClassLoader(context.getClassLoader()); |
| 53 | + try { |
| 54 | + callInitializers(context); |
65 | 55 | }
|
66 |
| - |
67 |
| - @Override |
68 |
| - protected void doStart() throws Exception { |
69 |
| - ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); |
70 |
| - Thread.currentThread().setContextClassLoader(this.context.getClassLoader()); |
71 |
| - try { |
72 |
| - callInitializers(); |
73 |
| - } |
74 |
| - finally { |
75 |
| - Thread.currentThread().setContextClassLoader(classLoader); |
76 |
| - } |
| 56 | + finally { |
| 57 | + Thread.currentThread().setContextClassLoader(classLoader); |
77 | 58 | }
|
| 59 | + } |
78 | 60 |
|
79 |
| - private void callInitializers() throws ServletException { |
80 |
| - try { |
81 |
| - setExtendedListenerTypes(true); |
82 |
| - for (ServletContextInitializer initializer : ServletContextInitializerConfiguration.this.initializers) { |
83 |
| - initializer.onStartup(this.context.getServletContext()); |
84 |
| - } |
85 |
| - } |
86 |
| - finally { |
87 |
| - setExtendedListenerTypes(false); |
| 61 | + private void callInitializers(WebAppContext context) throws ServletException { |
| 62 | + try { |
| 63 | + setExtendedListenerTypes(context, true); |
| 64 | + for (ServletContextInitializer initializer : this.initializers) { |
| 65 | + initializer.onStartup(context.getServletContext()); |
88 | 66 | }
|
89 | 67 | }
|
90 |
| - |
91 |
| - private void setExtendedListenerTypes(boolean extended) { |
92 |
| - try { |
93 |
| - this.context.getServletContext().setExtendedListenerTypes(extended); |
94 |
| - } |
95 |
| - catch (NoSuchMethodError ex) { |
96 |
| - // Not available on Jetty 8 |
97 |
| - } |
| 68 | + finally { |
| 69 | + setExtendedListenerTypes(context, false); |
98 | 70 | }
|
| 71 | + } |
99 | 72 |
|
| 73 | + private void setExtendedListenerTypes(WebAppContext context, boolean extended) { |
| 74 | + try { |
| 75 | + context.getServletContext().setExtendedListenerTypes(extended); |
| 76 | + } |
| 77 | + catch (NoSuchMethodError ex) { |
| 78 | + // Not available on Jetty 8 |
| 79 | + } |
100 | 80 | }
|
101 | 81 |
|
102 | 82 | }
|
0 commit comments