spring引导本机在构建期间启用https

6qfn3psc  于 2021-07-16  发布在  Java
关注(0)|答案(2)|浏览(452)

当我试图在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-图像选项
将下面的代码添加到plugin部分下的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>
cetgtptt

cetgtptt1#

打开您的配置文件,并添加以下行到该文件,我希望它将工作,因为它已经提到了错误以及。

--enable-url-protocols=https
t5zmwmid

t5zmwmid2#

或者如果您使用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>

相关问题