嵌入式tomcat不会扫描网页碎片

时间:2016-07-22 21:26:51

标签: java tomcat8 embedded-tomcat-8 web-fragment

我的嵌入式tomcat类识别web.xml和ServletContainerInitializers,但它不识别Web片段。 非常简单的代码。应该打开什么标志/配置来初始化网络片段?

    public static void main( String[] args ){

    Logger root = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
    root.setLevel(Level.INFO);

    String webappDirLocation = "src/main/webapp/";
    Tomcat tomcat = new Tomcat();

    tomcat.getHost().setAutoDeploy(true);
    tomcat.getHost().setDeployOnStartup(true);
    tomcat.setPort(8080);


    StandardContext ctx = null;
    try {
        ctx = (StandardContext) tomcat.addWebapp("/", new File(webappDirLocation).getAbsolutePath());
    } catch (ServletException e) {
        e.printStackTrace();
    }


    System.out.println("configuring app with basedir: " + new File("./" + webappDirLocation).getAbsolutePath());

    File additionWebInfClasses = new File("target/classes");
    WebResourceRoot resources = new StandardRoot(ctx);
    resources.addPreResources(new DirResourceSet(resources,
                                "/WEB-INF/classes",
                                additionWebInfClasses.getAbsolutePath(),
                                "/"));

    ctx.setResources(resources);
    ctx.setAltDDName( webappDirLocation + "WEB-INF/web.xml");
    ServletContextListener scl = new AdminServletContextListener();
    ctx.addApplicationEventListener(scl);

    try {

        tomcat.start();
        tomcat.getServer().start();
    } catch (LifecycleException e) {
        e.printStackTrace();
    }

    tomcat.getServer().await();
}

0 个答案:

没有答案