【问题标题】:Java Spring Boot- build MVN in dockerJava Spring Boot - 在 docker 中构建 MVN
【发布时间】:2022-01-09 01:59:50
【问题描述】:

我通过 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]

【问题讨论】:

    标签: java spring-boot docker maven jenkins


    【解决方案1】:

    来自Spring Boot Reference Doc, Chap. 8 Developer Tools

    8.5。远程应用程序

    Spring Boot 开发者工具不仅限于本地开发。您还可以在远程运行应用程序时使用多种功能。 远程支持是可选的,因为启用它可能会带来安全风险。只有在受信任的网络上运行或使用 SSL 保护时才应启用它。如果您无法使用这些选项,则不应使用 DevTools 的远程支持。 您永远不应该在生产部署中启用支持。

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

    要启用它,您需要确保 devtools 包含在重新打包的存档中,如下面的清单所示

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <excludeDevtools>false</excludeDevtools>
                </configuration>
            </plugin>
        </plugins>
    </build>
    

    那么您需要设置spring.devtools.remote.secret 属性。与任何重要的密码或秘密一样,该值应该是唯一且强大的,以便无法猜测或暴力破解。

    远程开发工具支持分两部分提供:一个接受连接的服务器端端点和一个您在 IDE 中运行的客户端应用程序。当设置spring.devtools.remote.secret 属性时,服务器组件会自动启用。客户端组件必须手动启动。

    注意:Spring WebFlux 应用程序不支持远程开发工具。


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

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

    然后我们可以参考小节:

    【讨论】:

    • 非常感谢
    猜你喜欢
    • 2022-01-10
    • 2017-02-11
    • 1970-01-01
    • 2018-09-03
    • 2018-05-22
    • 2020-05-16
    • 2018-05-02
    • 2018-08-26
    • 1970-01-01
    相关资源
    最近更新 更多