Question

I've read the Hot swapping in Spring Boot but didn't find something that will help my case.

I have a spring-boot app on embedded jetty servers using thymeleaf. My app will serve html,css,js(AngularJS) and REST services.

Folder structure is like this:

/java
   ----
/resources
   /static
       /js
       /css
   /templates (html)

pom.xml

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
    <exclusions>
        <exclusion>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
        </exclusion>
    </exclusions>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-jetty</artifactId>
</dependency>

But css/html/js is not hot deployed when I change them. I have to restart server every time. +bonus = when page loads it locks resources (js) and even Ant script cannot replace them.

Can I set scanIntervalSeconds anywhere?

--EDIT--

Main.java

@Configuration
@ComponentScan
@EnableJpaRepositories
@EnableAutoConfiguration
@Import({RepositoryRestMvcConfiguration.class, PersistenceConfig.class, ThymeleafConfig.class})
public class Main {

   public static void main(String[] args) throws Exception {
       SpringApplication.run(Main.class, args);
   }
}

I've run it by right click on class and Debug in IDEA.

Était-ce utile?

La solution

How are you launching the app? If you use an IDE with debug mode it should work (except for the locking problem which I believe is Windows OS), or if you launch it with "mvn spring-boot:run", or "gradle bootRun".

Autres conseils

I develop using NetBeans 8.0.1. I fixed the issue of not reloaded static resources in src/main/resources like css (in src/main/resources/resources/css (yes, really twice "resources"!), html-thymeleaf-templates (in src/main/resources/templates) the following way:

  • My Spring Boot webapp is a JAR project (pom.xml)
  • Add src/main/resources/application.properties:
    • spring.template.cache=false
    • spring.thymeleaf.cache=false
  • Added custom maven build: Project - Properties - Custom... - Goals...
  • Execute Goals: spring-boot:run
  • Set Properties:
    • jpda.listen=maven (to run it in debug mode)
    • Env.spring.profiles.active=DEV (optional, but I need it for different SpringConfig-....properties in development, production,...)

Just run the custom maven build for starting the webapp in debug mode. Changes in Thymeleaf-Templates (that are in src/main/resources/templates, eg. index.html (not .xhtml!)) are visible immediately on browser reload.

if you move the css and java script to a folder under src/main/java/webapp it should work.

for some reason resources under src/main/java/resources didnt seem to get hot deployed when changed.

to fix this as the above post suggested I added

  • spring.template.cache=false

  • spring.thymeleaf.cache=false to Application.properties inside the resources folder.

Note: I also added this

  • -javaagent:springloaded-1.2.0.RELEASE.jar -noverify

as a vm runtime argument.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top