Asked  9 Months ago    Answers:  5   Viewed   186 times

I have a Spring Boot Web Project that uses Joinfaces and Primefaces. The application extends from SpringBootServletInitializer and also generates a war file.

For development I start my Project (in Eclipse) using RunAs -> Spring Boot App. I've added the spring-boot-devtools dependency as described in the Developer Tools Docu. Everything seems to work, except that changes in a xhtml file also triggers the restart.

I've added the spring.devtools.restart.additional-exclude property in my application.yml to exclude also webapp/**. But this seems to have no effect, because a change still triggers the restart.

spring:
  devtools:
    restart:
      additional-exclude: webapp/**

My Project structure looks like:

src
 -main
  -java
  -resources
  -webapp
   - *.xhtml

But maybe I do not understand how to use the DevTools correct - Starting the application as Spring Boot App might not be the correct usage? Because if I place a file e.g. foo.txt under src/main/resources and update its content the application is also restarted (using the DevTools defaults (which should exclude /resources)).

Using:

  • Eclipse Oxygen.3a Release (4.7.3a)
  • Joinfaces 3.2.1 -> Spring Boot 2.0.2.RELEASE

 Answers

4

The solution to my main problem might be relatively easy.

I've added the webapp folder as Source Folder in Eclipse. As soon as I've removed the folder from the list of source folders, the reload was no longer triggered when I changed something in the xhtml files.

This answer gave me the idea, that the source folder might be the problem.

Monday, August 30, 2021
 
Claudio
 
5

Finally found the solution. It was much simpler than I thought.

Since I'm using war packaging I can use webapp's default behaviour. Everything under source folders trigger a restart, but resources under webapp are fetched at runtime, so there is no need to reload anything.

I just placed my static content under /webapp/static and then added the resource handler:

@Configuration
public class MvcConfig implements WebMvcConfigurer {
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/static/**").addResourceLocations("/static/"); 
    }
}

Just don't use the default Spring Boot placement for statics (basically anything under resources) and you'll be fine.

Sunday, August 29, 2021
 
2

To fix this problem I started running the application from within InteliJ. without having to add.

spring.devtools.restart.additional-paths=../submodule_6,../submodule_7

IntelliJ and spring-boot seem to work together very wel. The reason it was not working for me in the first place was because I was working from the commandline at first.

Difference between commandline and IDE

So spring-boot-devtools uses two classloaders to load an application. Jars will be loaded ones in the "Base classloader", your application will be loaded in the "restart classloader". This last classloader will restart everytime there is a change on the classpath.

Whenever running submodule_5 from the commandline, it will build the submodule_6 and submodule_7 and add the jars to the build of submodule_5. Whenever changes are made in submodule_6 and submodule_7 spring-boot won't even notice since it's only watching submodule_5 and has the jars it needs. Even if you would specifically tell it to also watch those submodules, it still won't rebuild those, it'll just keep using the jars it already has loaded in the "base classloader" (This is my assumption, I'm not 100% certain of the way it works).

Whenever running submodule_5 from the IDE, it won't create the jar of the submodule_6 and submodule_7. It will just use their classpath. This makes it so that changes in your intire project's classpath (all submodules) will trigger the automatic restart and the changes will be applied.

EXTRA

Whenever running from the IDE changes to resources like html-files, css-files, xml-files . . . won't trigger a restart since this is not a change in the classpath. But the changes will still be visible.

Monday, September 20, 2021
3

I followed this article https://github.com/spring-projects/spring-boot/issues/7479

So, to devtools works, you must add:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-devtools</artifactId>
    <optional>true</optional>
    <scope>runtime</scope>
</dependency>

The secret is add Optional True and Scope runtime.

Saturday, October 30, 2021
 
Andre
 
3

After googling and researching, there is a way to disable cache on a page. By opening the Developer Console, in the bottom right-hand column there is a cog. In that menu there is a checkbox Disable Cache that once enabled, fixes the problem.

Friday, November 5, 2021
 
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :  
Share