Reputation: 6517
I have a spring boot backend + separate (AngularJS based) client app. My build process first minifies the code of the client app and zips it and then installs it as a library in a local maven repo. The server refers the client library in its pom, so when the server is built the client gets packaged into the jar.
The issue is that when running the jar (with java -jar
) it sometimes takes ridiculously long to start (i.e. 5-10 minutes) or doesn't start at all (in a reasonable time) and sometimes starts straight away (5-10 seconds). I was wondering what might be the cause? Could it have to do with the client zip being too large in size (and maybe gets somehow cached at times)?
Edit: When the jar is ran (via java -jar server.jar
). Afterwars the log goes like
Starting Application ... with PID ...
Mapping servlet: 'dispatcherServlet' to [/]
Mapping filter: ....
Mapping filter: 'requestContextFilter' to [/*]
and gets stuck at this filter mapping.
Upvotes: 0
Views: 407
Reputation: 31463
You have to inspect the spring-boot log files to understand where the app is taking time. Try to set the log-level on TRACE and watch the timestamps.
In spring-boot you can add ResourceHandlers to serve static content. You have to do a similar override, as documented in the link:
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
if (!registry.hasMappingForPattern("/webjars/**")) {
registry.addResourceHandler("/webjars/**").addResourceLocations(
"classpath:/META-INF/resources/webjars/");
}
if (!registry.hasMappingForPattern("/**")) {
registry.addResourceHandler("/**").addResourceLocations(
RESOURCE_LOCATIONS);
}
}
This way you can distribute your client code as a separate package, and in the deployment process you have to put that package (and possibly unpack it) in the right place, so that it can be picked up by the resource handler.
Upvotes: 1