9

In the Spring Boot make the frontend part update without restarting the application?

slartidan
  • 18,794
  • 12
  • 78
  • 122
wss.world
  • 281
  • 1
  • 4
  • 5

6 Answers6

11

Best solution i found for static webpages and css is https://stackoverflow.com/a/39334398/6467734 and for loading code (including jsp) without restarting the server you can use Spring Boot Devtools dependency

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-devtools</artifactId>
    <optional>true</optional>
</dependency>
rolve
  • 9,410
  • 4
  • 51
  • 71
Amrut Prabhu
  • 119
  • 1
  • 5
5

I'm an Eclipse user (via Spring Tool Suite) and I never have any problems with reloading static content if the app is running in debug mode. Just right click on the main class and "Debug As->Java App" (or "Spring Boot App", it's the same). You have to also ensure that the workspace is configured to "Build Automatically", but that is the default as far as I know.

I can't offer such specific advice for users of other IDEs, but I'm sure they all have the same feature.

Dave Syer
  • 54,455
  • 10
  • 152
  • 139
4

In the Intellij IDEA run up your project in Debug mode and you will get the same effect.

Or externalize your static .

@Configuration
public class MvcConfig extends WebMvcConfigurerAdapter {

    private String extStaticPath = "/var/www/site1/";

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/static/**")
                .addResourceLocations(extStaticPath)
                .setCachePeriod(0);
    }
}
slartidan
  • 18,794
  • 12
  • 78
  • 122
max_dev
  • 545
  • 1
  • 6
  • 14
2

for JSP files try to set server.jsp-servlet.init-parameters.development=true

arbuzov
  • 853
  • 6
  • 10
1

You can try developer tools from Spring boot. Applications that use spring-boot-devtools will automatically restart whenever files on the classpath change. More info how it works here

nav3916872
  • 940
  • 12
  • 18
0

Add the following to src/main/resources/application.properties:

spring.resources.static-locations[0]=file:src/main/resources/static/
spring.resources.static-locations[1]=classpath:/static/

The "file:" causes the content to be reloaded on refreshing the browser

Alternatively, the file resource locations can be discovered at runtime and added programmatically. I hope that helps.

Saurabh Verma
  • 1,110
  • 1
  • 17
  • 30