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);
}
};
}
什麼值設置爲contextPath
和ResourceBase
,這樣我可以運行我的指數.html這是在前端模塊?網址如何顯示?
謝謝:)
當您使用'./gradlew bootRun'運行應用程序時,這是真的,但是當您構建獨立的jar時,那麼將如何指定靜態內容的位置,因爲在JAR部署中,src/main/resources/static文件夾不是在你的類路徑中? – user320599 2017-01-17 22:29:01
該特定的文件夾不在類路徑中,但「靜態」文件夾及其內容與構建系統在jar中包含它們一樣。 – 2017-01-18 08:28:46