Add web application context to Jetty

后端 未结 2 1386
礼貌的吻别
礼貌的吻别 2020-12-16 07:39

I want to create simple Spring MVC \"Hello world\" application that runs under Jetty (wich is a part of application).

Structure of my application is:



        
相关标签:
2条回答
  • 2020-12-16 08:15

    The application-context.xml file should be placed inside the WEB-INF directory.

    0 讨论(0)
  • 2020-12-16 08:28

    If you are running with an exploded war directory try setting the resource base property explicitly:

    context.setResourceBase("/path-to-your-project/WebContent");
    context.setDescriptor("/path-to-your-project/WebContent/WEB-INF/web.xml");
    

    or if you are deploying the war itself you can just use:

      context.setWar("/path-to-your-project/WebContent");
    

    Here are the docs showing embedded Jetty samples.

    In the context of your app:

    Resource jettyConfig = Resource.newSystemResource("jetty.xml");
    XmlConfiguration configuration = new XmlConfiguration(jettyConfig.getInputStream());
    Server server = (Server)configuration.configure();
    
    WebAppContext wac = new WebAppContext();
    wac.setResourceBase(".");
    wac.setDescriptor("WEB-INF/web.xml");
    wac.setContextPath("/");
    wac.setParentLoaderPriority(true);
    server.setHandler(wac);
    
    server.start();
    

    This assumes that your base path where you're running your server from is the same as the path to the web content.

    0 讨论(0)
提交回复
热议问题