Hot-swap not working in Spring Boot application

Answered

I am out of ideas.

I have followed these instructions: Intellij IDEA – Spring boot reload static file is not working

and searched through all kinds of pages but hot reloading is simply not working.

I have added the devtools

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

I have enabled the automatic build:

and I have enabled compiler.automake.allow.when.app.running

and I set On 'Update' action to Update classes and resources after trying to user a Spring Boot run configuration (as suggested here).

But it's still not working.


This here is my entire pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>audio-platform</groupId>
    <artifactId>server</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <spring.boot.version>2.2.2.RELEASE</spring.boot.version>
    </properties>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.2.2.RELEASE</version>
        <relativePath/>
    </parent>

    <dependencies>

        <!-- Spring Framework Boot -->

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-rest</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-logging</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-mail</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.ws</groupId>
            <artifactId>spring-ws-core</artifactId>
        </dependency>

        <!-- Spring Security -->

        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-jwt</artifactId>
            <version>1.0.9.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.security.oauth</groupId>
            <artifactId>spring-security-oauth2</artifactId>
            <version>2.3.2.RELEASE</version>
        </dependency>

        <!-- Spring Docs (Swagger) -->

        <!-- TODO After version upgrades check https://github.com/springdoc/springdoc-openapi/issues/133 -->

        <dependency>
            <groupId>org.springdoc</groupId>
            <artifactId>springdoc-openapi-core</artifactId>
            <version>1.1.49</version>
            <exclusions>
                <exclusion>
                    <groupId>io.github.classgraph</groupId>
                    <artifactId>classgraph</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <dependency>
            <groupId>org.springdoc</groupId>
            <artifactId>springdoc-openapi-ui</artifactId>
            <version>1.1.49</version>
        </dependency>

        <dependency>
            <groupId>io.github.classgraph</groupId>
            <artifactId>classgraph</artifactId>
            <version>4.8.44</version>
        </dependency>

        <!-- Sentry -->

        <dependency>
            <groupId>io.sentry</groupId>
            <artifactId>sentry-spring</artifactId>
            <version>1.7.23</version>
        </dependency>

        <!-- PostgreSQL Driver -->

        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <version>42.1.4</version>
        </dependency>

        <!-- Flyway -->

        <dependency>
            <groupId>org.flywaydb</groupId>
            <artifactId>flyway-core</artifactId>
        </dependency>

        <dependency>
            <groupId>org.flywaydb.flyway-test-extensions</groupId>
            <artifactId>flyway-spring-test</artifactId>
            <version>5.0.0</version>
            <scope>test</scope>
        </dependency>

    </dependencies>

    <build>
        <plugins>

            <!-- Java version -->

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>

        </plugins>

    </build>

    <!-- Dependency Management -->

    <dependencyManagement>

        <dependencies>

            <!-- Import dependency management from Spring Boot -->

            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-dependencies</artifactId>
                <version>${spring.boot.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>

        </dependencies>

    </dependencyManagement>

</project>

I am on Ubuntu 18.04 LTS and the directory is a local path, not a symlink or anything. All files belong to me (my user) etc and all permissions are as they should be.

What could I be still missing?

0
8 comments
Avatar
Permanently deleted user

What I might add:

 

This project is basically a copy & paste version of another project but with a lot of parts removed. 

I have another project on my machine which works just fine. 

The only way I was / am able to make this work is to enable hot-swapping whenever I am un-focusing the IntelliJ window ("frame").

0

Do you actually perform the Update action or Save the project after changes in the code? Does Build | Build work?

See https://intellij-support.jetbrains.com/hc/en-us/community/posts/360003328879-Can-t-get-devtools-auto-build-service-working-on-Windows-?page=1#community_comment_360000427059 for the relevant options affecting automatic compilation.

0
Avatar
Permanently deleted user

I don't really know what an "Update action" even is. 

The other project I have does behave totally different. Like - there's somethign fundamentally wrong with this particular project.

If I hit Build | Build I get

 

It's so weird! 

Sometimes the server won't start because it does not pick up the properties fiel application-local.properties.

The fix: I change a character and now all of a sudden it works again.

That's why I thought maybe it's a permissions issue but everything is the same for the other project where all these things work O_o

0

See https://www.jetbrains.com/help/idea/updating-applications-on-application-servers.html .

The error you have is that the changes you try to hotswap are not supported by the JVM.

In order to investigate further we'll need a sample project and the exact steps to reproduce as already requested in my comment here several days ago: https://stackoverflow.com/questions/59847662/why-is-spring-boot-hot-reload-not-working#comment105828969_59847662 .

0
Avatar
Permanently deleted user

I kind of "fixed" this issue by just using a Spring run configuration and go with reaload-on-update setting.

However, what is still driving me mad is that after hot swapping the server might do its quick reboot but for some reason it does not pick up my application-local.properties file anymore.

I see in the log that the profile was set by -Dspring.profiles.active=local

The following profiles are active: local

but then the application will crash because it keeps telling me that the 'url' attribute was not spcified for my data source:

Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.

 

Even restarting the server as a whole does not help.

 

I literally have to edit the application-local.properties file by inserting a character (space, return, comment) in order for this to work again.

It's driving me nuts because there is no issue like that in my other project ..

 

Any ideas what this could cause? I'm just glad I have this issue at home and not at work ..

0

No ideas, need a test case to reproduce/debug.

0

@...

The following two settings worked for me to auto restart the server.

1. Add war exploded artifacts.

2. run configuration (update classes and resources.)

 

 

 

 

1

Chalapathi Chitturi Thank you. Got that problem again, came back to this post and found that adding the artifact did the trick!

0

Please sign in to leave a comment.