2015-02-07 146 views
0

我正在开发一个多模块弹簧启动项目。我的项目结构看起来像在春季启动时配置码头

  • myProject的(父)
  • 前端
    • 的src/main /资源
      • 前端
        • 的index.html
  • 其余
    • 的src /主/ JAVA
      • com。示例
        • MyWebApp.java
      • com.example.config
        • WebAppConfig.java

我试图通过注入JettyServerCustomizer豆在WebAppConfig配置码头如下

@Bean 
public JettyServerCustomizer customizeJettyServer() 
{ 
    return new JettyServerCustomizer() 
    { 

     @Override 
     public void customize(final Server server) 
     { 
      ContextHandler frontEndContext = new ContextHandler(); 
      frontEndContext.setContextPath(""); //what should be here 
      frontEndContext.setResourceBase("");//what should be here 
      ResourceHandler frontEndResourceHandler = new ResourceHandler(); 
      frontEndResourceHandler.setWelcomeFiles(new String[] { "index.html" }); 
      frontEndContext.setHandler(frontEndResourceHandler); 
      ContextHandlerCollection contexts = new ContextHandlerCollection(); 
      contexts.setHandlers(new Handler[] { frontEndContext}); 
      server.setHandler(contexts); 
     } 
    }; 
} 

什么值设置为contextPathResourceBase,这样我可以运行我的指数.html这是在前端模块?网址如何显示?

谢谢:)

回答

1

春天开机即可serve static content你。不要试图配置Jetty,而是将您的静态内容置于src/main/resources/static之下,并且它们将从类路径直接加载。

+0

当您使用'./gradlew bootRun'运行应用程序时,这是真的,但是当您构建独立的jar时,那么将如何指定静态内容的位置,因为在JAR部署中,src/main/resources/static文件夹不是在你的类路径中? – user320599 2017-01-17 22:29:01

+0

该特定的文件夹不在类路径中,但“静态”文件夹及其内容与构建系统在jar中包含它们一样。 – 2017-01-18 08:28:46