Spring 3.1 WebApplicationInitializer & Embedded Jetty 8 AnnotationConfiguration

后端 未结 13 1162
無奈伤痛
無奈伤痛 2020-12-13 14:16

I\'m trying to create a simple webapp without any XML configuration using Spring 3.1 and an embedded Jetty 8 server.

However, I\'m struggling to get Jetty to recogni

13条回答
  •  甜味超标
    2020-12-13 14:41

    For Jetty 9, if you have webjars, the solution provided does not work straight away as those Jars need to be on the classpath and the JAR contents need to be available as resources for your webapp. So, for that to work together with webjars, the config would have to be:

    context.setExtraClasspath(pathsToWebJarsCommaSeparated);
    context.setAttribute(WebInfConfiguration.WEBINF_JAR_PATTERN, ".*\\.jar$");
    context.setAttribute(WebInfConfiguration.CONTAINER_JAR_PATTERN, ".*\\.jar$");
    context.setConfigurations(
            new org.eclipse.jetty.webapp.Configuration[] { 
            new WebInfConfiguration(), new MetaInfConfiguration(),
            new AnnotationConfiguration() {
                @Override
                public void preConfigure(WebAppContext context) throws Exception {
                    final ClassInheritanceMap map = new ClassInheritanceMap();
                    final ConcurrentHashSet set = new ConcurrentHashSet<>();
                    set.add(MyWebAppInitializer.class.getName());
                    map.put(WebApplicationInitializer.class.getName(), set);
                    context.setAttribute(CLASS_INHERITANCE_MAP, map);
                    _classInheritanceHandler = new ClassInheritanceHandler(map);
                }
            } });
    

    The order here is important (WebInfConfiguration has to come before MetaInf).

提交回复
热议问题