如何解决Spring Boot 本机在构建期间启用 https
当我尝试在 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
<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>
解决方法
或者如果您使用 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>
,
打开您的配置文件并将以下行添加到该文件中,我希望它会起作用,正如错误中提到的那样。
--enable-url-protocols=https
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。