1818 */
1919package de .rwth .idsg .steve ;
2020
21- import org .apache .cxf .transport .servlet .CXFServlet ;
2221import org .apache .tomcat .InstanceManager ;
2322import org .apache .tomcat .SimpleInstanceManager ;
2423import org .eclipse .jetty .ee10 .apache .jsp .JettyJasperInitializer ;
25- import org .eclipse .jetty .ee10 .servlet .FilterHolder ;
2624import org .eclipse .jetty .ee10 .servlet .ServletContextHandler ;
27- import org .eclipse .jetty .ee10 .servlet .ServletHolder ;
2825import org .eclipse .jetty .ee10 .webapp .WebAppContext ;
2926import org .eclipse .jetty .rewrite .handler .RedirectPatternRule ;
3027import org .eclipse .jetty .rewrite .handler .RewriteHandler ;
3431import org .eclipse .jetty .server .handler .gzip .GzipHandler ;
3532import org .eclipse .jetty .util .component .AbstractLifeCycle ;
3633import org .springframework .core .io .ClassPathResource ;
37- import org .springframework .security .web .context .AbstractSecurityWebApplicationInitializer ;
38- import org .springframework .web .context .ContextLoaderListener ;
39- import org .springframework .web .context .support .AnnotationConfigWebApplicationContext ;
40- import org .springframework .web .filter .DelegatingFilterProxy ;
41- import org .springframework .web .servlet .DispatcherServlet ;
42-
43- import jakarta .servlet .DispatcherType ;
4434
4535import java .io .IOException ;
46- import java .util .EnumSet ;
4736import java .util .HashSet ;
4837
4938import static de .rwth .idsg .steve .SteveConfiguration .CONFIG ;
5443 */
5544public class SteveAppContext {
5645
57- private final AnnotationConfigWebApplicationContext springContext ;
46+ // scan all jars in the classpath for ServletContainerInitializers
47+ // (e.g. Spring's WebApplicationInitializer)
48+ private static final String SCAN_PATTERN = ".*\\ .jar$|.*/classes/.*" ;
49+
5850 private final WebAppContext webAppContext ;
5951
6052 public SteveAppContext () {
61- springContext = new AnnotationConfigWebApplicationContext ();
62- springContext .scan ("de.rwth.idsg.steve.config" );
63- webAppContext = initWebApp ();
53+ webAppContext = new WebAppContext ();
54+ webAppContext .setContextPath (CONFIG .getContextPath ());
55+ webAppContext .setBaseResourceAsString (getWebAppURIAsString ());
56+
57+ // if during startup an exception happens, do not swallow it, throw it
58+ webAppContext .setThrowUnavailableOnStartupException (true );
59+
60+ // Disable directory listings if no index.html is found.
61+ webAppContext .setInitParameter ("org.eclipse.jetty.servlet.Default.dirAllowed" , "false" );
62+
63+ // Crucial for Spring's WebApplicationInitializer to be discovered
64+ // and for the DispatcherServlet to be initialized.
65+ // It tells Jetty to scan for classes implementing WebApplicationInitializer.
66+ // The pattern ensures that Jetty finds the Spring classes in the classpath.
67+ //
68+ // https://jetty.org/docs/jetty/12.1/programming-guide/maven-jetty/jetty-maven-plugin.html
69+ // https://jetty.org/docs/jetty/12.1/operations-guide/annotations/index.html#og-container-include-jar-pattern
70+ webAppContext .setAttribute ("org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern" , SCAN_PATTERN );
71+
72+ initJSP (webAppContext );
6473 }
6574
6675 public ContextHandlerCollection getHandlers () {
@@ -80,36 +89,6 @@ private Handler getWebApp() {
8089 return new GzipHandler (webAppContext );
8190 }
8291
83- private WebAppContext initWebApp () {
84- WebAppContext ctx = new WebAppContext ();
85- ctx .setContextPath (CONFIG .getContextPath ());
86- ctx .setBaseResourceAsString (getWebAppURIAsString ());
87-
88- // if during startup an exception happens, do not swallow it, throw it
89- ctx .setThrowUnavailableOnStartupException (true );
90-
91- // Disable directory listings if no index.html is found.
92- ctx .setInitParameter ("org.eclipse.jetty.servlet.Default.dirAllowed" , "false" );
93-
94- ServletHolder web = new ServletHolder ("spring-dispatcher" , new DispatcherServlet (springContext ));
95- ServletHolder cxf = new ServletHolder ("cxf" , new CXFServlet ());
96-
97- ctx .addEventListener (new ContextLoaderListener (springContext ));
98- ctx .addServlet (web , CONFIG .getSpringMapping ());
99- ctx .addServlet (cxf , CONFIG .getCxfMapping () + "/*" );
100-
101- // add spring security
102- ctx .addFilter (
103- // The bean name is not arbitrary, but is as expected by Spring
104- new FilterHolder (new DelegatingFilterProxy (AbstractSecurityWebApplicationInitializer .DEFAULT_FILTER_NAME )),
105- CONFIG .getSpringMapping () + "*" ,
106- EnumSet .allOf (DispatcherType .class )
107- );
108-
109- initJSP (ctx );
110- return ctx ;
111- }
112-
11392 private Handler getRedirectHandler () {
11493 RewriteHandler rewrite = new RewriteHandler ();
11594 for (String redirect : getRedirectSet ()) {
0 commit comments