【发布时间】:2018-08-10 22:53:29
【问题描述】:
我的spring-boot项目是这样的:
project
|__ build.gradle
|__ settings.gradle
|__ application
|__ library
|__ web
|__ application
|__ library
|__ web
应用程序包含实现 WebMvcConfigurer 的主类和 MvcConfig 类:
@Configuration
public class MvcConfig implements WebMvcConfigurer {
@Override
public void addResourceHandlers (ResourceHandlerRegistry registry) {
String workingDirectory = System.getProperty("user.dir");
registry.addResourceHandler("/**")
.addResourceLocations("file:///" + workingDirectory + "/../web/dist/");
}
@Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/").setViewName("forward:/index.html");
}
}
当我运行 : gradlew :application:bootRun => 一切正常。
我的 web 目录是一个 angularJS 应用程序,gulp 在 dist 目录中构建它。 (我正在使用 moowork 节点和 gulp gradle 插件)
但现在我想将我的所有应用程序放在一个使用 bootJar 生成的胖 jar 中。
java -jar application.jar (will run all the app)
application.jar 包含 web.jar,其中包含 dist 目录中的所有内容。
gradlew :application:bootJar 生成一个包含所有内容(库、spring-boot web)的 jar,但是当我启动它时,它找不到我的 index.html
我知道我必须更改 addResourceLocations 参数,但我需要一些帮助才能做到这一点。 我试过(没有成功):
.addResourceLocations("classpath:/web/");
【问题讨论】:
标签: java spring spring-boot gradle gradlew