【问题标题】:Spring boot native enable https during buildSpring Boot Native 在构建期间启用 https
【发布时间】:2021-03-20 05:09:10
【问题描述】:

当我尝试在 Spring 原生应用程序中使用 HTTPS 时出现以下错误。

java.net.MalformedURLException: Accessing an URL protocol that was not enabled. The URL protocol HTTPS is supported but not enabled by default. It must be enabled by adding the --enable-url-protocols=https option to the native-image command.

HTTPS URL 协议未启用。请帮助我在构建期间启用。

更新

找到解决方案,查看 spring 本机文档。 https://docs.spring.io/spring-native/docs/current/reference/htmlsingle/#native-image-options

将以下代码添加到插件部分下的 pom.xml

<BP_NATIVE_IMAGE_BUILD_ARGUMENTS>--enable-https</BP_NATIVE_IMAGE_BUILD_ARGUMENTS>

更新后的 pom.xml 如下所示。

<plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <configuration>
        <image>
            <builder>paketobuildpacks/builder:tiny</builder>
            <env>
                <BP_NATIVE_IMAGE>true</BP_NATIVE_IMAGE>
                <BP_NATIVE_IMAGE_BUILD_ARGUMENTS>--enable-https</BP_NATIVE_IMAGE_BUILD_ARGUMENTS>
            </env>
        </image>
    </configuration>
</plugin>

【问题讨论】:

  • 请不要在问题中回答你的问题。而是在实际答案中回答它,并在几天后接受它,如果它仍然是最佳答案。这样其他人更容易找到答案,并且可以很容易地看到问题已得到解答。你也可能会得到答案。

标签: java spring spring-boot graalvm spring-native


【解决方案1】:

或者如果您使用 graalvm 原生图像插件:

                     <plugin>
                        <groupId>org.graalvm.nativeimage</groupId>
                        <artifactId>native-image-maven-plugin</artifactId>
                        <version>21.0.0</version>
                        <configuration>
                            <!-- The native image build needs to know the entry point to your application -->
                            <mainClass>com.dccorp.nativeapps.NativeCloudStreamsApplication</mainClass>
                            <buildArgs>
                                <!-- uncomment to generate dump file for graalvm dashboard analysis.-->
                                <!-- -H:DashboardDump=dumpfileoversizedbuildArgs-->
                                <!-- -H:+DashboardAll-->
                                <!-- you can provide additional params. -->
                                <!-- -H:DynamicProxyConfigurationFiles=classes/proxy-config.json-->
                                <!-- -H:ReflectionConfigurationFiles=classes/reflect-config.json-->
                                --enable-url-protocols=http
                            </buildArgs>
                        </configuration>
                        <executions>
                            <execution>
                                <goals>
                                    <goal>native-image</goal>
                                </goals>
                                <phase>package</phase>
                            </execution>
                        </executions>
                    </plugin>

【讨论】:

    【解决方案2】:

    打开您的配置文件并将以下行添加到该文件中,我希望它会起作用,正如错误中提到的那样。

    --enable-url-protocols=https
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-08-19
    • 1970-01-01
    • 1970-01-01
    • 2019-02-22
    • 1970-01-01
    • 2020-06-22
    • 1970-01-01
    • 2018-03-26
    相关资源
    最近更新 更多