Java Spring 在 docker 中引导构建 MVN

Java Spring Boot- build MVN in docker

我用MVN构建了一个项目。它成功但调用 API,我有一个问题:

> 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]

来自 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.

(我解释:我们永远不应该(因为不要为不同的环境构建不同的工件)这样做,但我们可以:)

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.


所以对于远程开发者工具,我们必须:

  • 考虑所有(以上)警告和建议
  • 在我们的 maven/gradle (spring-boot) 插件上设置 excludeDevtools
  • 设置spring.devtools.remote.secretapplication.,秘密,非空)属性

然后我们可以参考小节: