Issue
I build a project by MVN. It success but call API, I have an issue:
> 2022-01-09 08:47:28.680 INFO 1 --- [nio-8083-exec-1] o.s.web.servlet.DispatcherServlet : Completed initialization in 8 ms
> 2022-01-09 08:47:28.691 ERROR 1 --- [nio-8083-exec-1]o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Filter execution threw an exception] with root cause
>
> java.lang.ClassNotFoundException:org.springframework.boot.devtools.remote.client.HttpHeaderInterceptor
> at java.net.URLClassLoader.findClass(URLClassLoader.java:382) ~[na:1.8.0_212]
> at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[na:1.8.0_212]
> at org.springframework.boot.loader.LaunchedURLClassLoader.loadClass(LaunchedURLClassLoader.java:151) ~[app.jar:0.0.1-SNAPSHOT]
> at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[na:1.8.0_212]
Solution
From Spring Boot Reference Doc, Chap. 8 Developer Tools :
8.5. Remote Applications
The Spring Boot developer tools are not limited to local development. You can also use several features when running applications remotely. Remote support is opt-in as enabling it can be a security risk. It should only be enabled when running on a trusted network or when secured with SSL. If neither of these options is available to you, you should not use DevTools' remote support. You should never enable support on a production deployment.
(I interpret: we should never-ever (because don't build different artifacts for different environments) do it, but we can:)
To enable it, you need to make sure that devtools is included in the repackaged archive, as shown in the following listing:
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludeDevtools>false</excludeDevtools>
</configuration>
</plugin>
</plugins>
</build>
Then you need to set the
spring.devtools.remote.secret
property. Like any important password or secret, the value should be unique and strong such that it cannot be guessed or brute-forced.
Remote devtools support is provided in two parts: a server-side endpoint that accepts connections and a client application that you run in your IDE. The server component is automatically enabled when the
spring.devtools.remote.secret
property is set. The client component must be launched manually.
Note: Remote devtools is not supported for Spring WebFlux applications.
So for remote devtools, we must:
- consider all (above) warnings & recommendations
- set
excludeDevtools
on our maven/gradle (spring-boot) plugin - set
spring.devtools.remote.secret
(application.
, secret, non-empty) property
Then we can refer to the sub-sections:
Answered By - xerx593
Answer Checked By - Dawn Plyler (JavaFixing Volunteer)