3

当我尝试在 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>
4

2 回答 2

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>
于 2021-04-07T18:10:29.410 回答
-1

打开您的配置文件并将以下行添加到该文件中,我希望它会起作用,因为它也已在错误中提到。

--enable-url-protocols=https
于 2021-03-20T05:14:58.013 回答