简体   繁体   中英

Spring boot, gradle, angularJS and a fat jar

My spring-boot project is like this:

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

application contains the main and a MvcConfig class that implements WebMvcConfigurer:

@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");
    }
}

When I run : gradlew :application:bootRun => everything works fine.

My web directory is a angularJS application and gulp builds it in a dist repertory. (I'm using moowork node and gulp gradle plugin)

But now I want to a have all my application in one fat jar generated with bootJar.

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

application.jar contains web.jar wich contains all that is inside the dist repertory.

gradlew :application:bootJar generates a jar with everything (library, spring-boot web) but when I launch it, it doesn't find my index.html

I know that I have to change the addResourceLocations arguments but I need some help to do it. I have tried (without success):

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

好吧,答案很简单:由于web.jar包含dist内部的所有内容,因此我只需要这样做:

.addResourceLocations("classpath:/");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM