簡體   English   中英

彈簧靴,gradle,angularJS和一個胖子罐

[英]Spring boot, gradle, angularJS and a fat jar

我的spring-boot項目是這樣的:

project
|__ build.gradle
|__ settings.gradle
   |__ application
   |__ library
   |__ web
|__ application
|__ library
|__ web

應用程序包含main和一個實現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生成的胖罐中。

java -jar application.jar (will run all the app)

application.jar包含web.jar,其中包含dist目錄中的所有內容。

gradlew:application:bootJar生成一個包含所有內容的jar(庫,spring-boot網絡),但是當我啟動它時,找不到我的index.html

我知道我必須更改addResourceLocations參數,但是我需要一些幫助。 我已經嘗試過(沒有成功):

.addResourceLocations("classpath:/web/");

好吧,答案很簡單:由於web.jar包含dist內部的所有內容,因此我只需要這樣做:

.addResourceLocations("classpath:/");

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM