Intellij, Spring dev tools remote, Docker, error U

2020-03-19 03:02发布

问题:

Im trying to use Spring Boot Dev tools (Spring Remote), and automatically upload recompiled files to my docker container.

I keep receiving Unexpected 404 response uploading class files

This is my docker file:

FROM java:8
WORKDIR /first
ADD ./build/libs/first.jar /first/first.jar
EXPOSE 8080
RUN bash -c 'touch /first/first.jar'
ENTRYPOINT ["java","-Dspring.data.mongodb.uri=mongodb://mongodb/micros", "-Djava.security.egd", "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005","-jar", "first.jar"]

This is my configuration and the configuration

And this is the error I'm receiving:

回答1:

As of Spring Boot 1.5.0, devtools defaults were changed to exclude the devtools from fat jars.

If you want to include them, you have to set the excludeDevtools flag to false.

However, the devtools documentation doesn't explain how to do this. The necessary documentation is actually in the spring-boot-gradle-plugin documentation.

To do it, you can put this snippet of code in your build.gradle file:

bootRepackage {
    excludeDevtools = false
}

Unfortunately, this was buggy at first and had no effect as of Spring Boot 1.5.0. The workaround was to do this instead:

springBoot {
    excludeDevtools = false
}

However, I have verified that the bootRepackage approach works for Spring Boot 1.5.8 .



回答2:

I got the same issues as yours while using docker-compose to compose my application ( a web service + redis server + mongo server ).

As the Spring developer tools document point out "Developer tools are automatically disabled when running a fully packaged application. If your application is launched using java -jar or if it’s started using a special classloader, then it is considered a “production application”."

I think when we running Spring Web Application inside Docker container, the developer tool is disabled then we cant remotely restart it.

Currently, I'm running my web application on the host machine and set the redis server, mongo server inside containers so I can restart the web app quickly when the code is changing in development process.



回答3:

In my case I had to put the application context on the argument of the IDE RemoteSpringApplication configuration.

For example, my application root context was /virtue so I had to configure it like so: