Reputation: 476
I have developed a REST API with Spring Boot. I've used Angular for front-end and added its files to resources/static. Everything is working fine.
I currently deploy my application in fat JAR format. The spring boot application does not change very often but I have to change the front-end day by day. Is there any way to somehow inject the updated angular files to currently deployed JAR file? Or I should change the packaging to WAR and use external tomcat server?
Upvotes: 0
Views: 1140
Reputation: 251
In theory you can define any directory as source of your static files:
@Configuration
public class ResourceConfig implements WebMvcConfigurer{
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry
.addResourceHandler("/resources/**")
.addResourceLocations("file:///e:/app/resources/public/")
//other options
}}
No idea if it works in production, I've done some prototyping only. There is a bit more on Baeldung page (old article, but updated to Spring 5), and official spring docs
Upvotes: 0
Reputation: 737
Literally, yes, you can update an existing jar file by using the jar command:
jar uf jar-file input-file(s)
However, you still need to restart the process.
I assume, your question is more about hot deployment
or hot swapping
- how to add new files without stopping a running process.
In the case of a spring-boot application with an embedded Tomcat in a production environment, you still need to restart it.
So, the easiest way to achieve a hot deploy of an angular front-end is to split your jar, extract an angular app, and deploy it separately.
As you mentioned, you can deploy a war with an angular app to a Tomcat instance. If you use a Linux based machine, I would recommend packing the angular app to a tar/zip and extracting it to an Apache httpd or nginx web server.
Also, you can use, for example, docker-compose for live reloading.
In the case of a development environment, it's much easier, because you can make use of an IDE support combined with spring-boot-devtools to achieve hot swapping, more explained at spring-boot docs.
Upvotes: 1