gpt4 book ai didi

java - Spring Boot native 在构建期间启用 https

转载 作者:行者123 更新时间:2023-12-05 06:03:10 24 4
gpt4 key购买 nike

当我尝试在 spring native 应用程序中使用 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 协议(protocol)。请在构建期间帮助我启用。

更新

找到解决方案,查看 spring native 文档。 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>

最佳答案

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

关于java - Spring Boot native 在构建期间启用 https,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66718428/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com