我有一个spring本机应用程序,可以对另一个服务进行http调用。我使用本机imagemaven插件(mvn-pnativeimagepackage)编译了该服务。当我的应用程序尝试进行http调用时,我看到了这样一条消息:“支持url协议http,但默认情况下不启用。必须通过将--enable url protocols=http选项添加到本机映像命令来启用它。”
org.springframework.web.client.ResourceAccessException: I/O error on GET request for "http://localhost:8081/v1/test": Accessing an URL protocol that was not enabled. The URL protocol http is supported but not enabled by default. It must be enabled by adding the --enable-url-protocols=http option to the native-image command.; nested exception is java.net.MalformedURsampleception: Accessing an URL protocol that was not enabled. The URL protocol http is supported but not enabled by default. It must be enabled by adding the --enable-url-protocols=http option to the native-image command.
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:785) ~[com.app.demo.sample.SampleApplication:5.3.4]
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:711) ~[com.app.demo.sample.SampleApplication:5.3.4]
at org.springframework.web.client.RestTemplate.getForEntity(RestTemplate.java:361) ~[com.app.demo.sample.SampleApplication:5.3.4]
----
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515) ~[na:na]
at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:305) ~[na:na]
at java.util.concurrent.ScheduledThreadPoosampleecutor$ScheduledFutureTask.run(ScheduledThreadPoosampleecutor.java:305) ~[na:na]
at java.util.concurrent.ThreadPoosampleecutor.runWorker(ThreadPoosampleecutor.java:1128) ~[na:na]
at java.util.concurrent.ThreadPoosampleecutor$Worker.run(ThreadPoosampleecutor.java:628) ~[na:na]
at java.lang.Thread.run(Thread.java:834) ~[na:na]
at com.oracle.svm.core.thread.JavaThreads.threadStartRoutine(JavaThreads.java:519) ~[na:na]
at com.oracle.svm.core.posix.thread.PosixJavaThreads.pthreadStartRoutine(PosixJavaThreads.java:192) ~[na:na]
Caused by: java.net.MalformedURsampleception: Accessing an URL protocol that was not enabled. The URL protocol http is supported but not enabled by default. It must be enabled by adding the --enable-url-protocols=http option to the native-image command.
at com.oracle.svm.core.jdk.JavaNetSubstitutions.unsupported(JavaNetSubstitutions.java:215) ~[na:na]
at com.oracle.svm.core.jdk.JavaNetSubstitutions.getURLStreamHandler(JavaNetSubstitutions.java:172) ~[na:na]
at java.net.URL.getURLStreamHandler(URL.java:71) ~[na:na]
at java.net.URL.<init>(URL.java:651) ~[na:na]
at java.net.URL.fromURI(URL.java:719) ~[na:na]
at java.net.URI.toURL(URI.java:1116) ~[na:na]
at org.springframework.http.client.SimpleClientHttpRequestFactory.createRequest(SimpleClientHttpRequestFactory.java:145) ~[na:na]
at org.springframework.http.client.support.HttpAccessor.createRequest(HttpAccessor.java:124) ~[na:na]
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:772) ~[com.app.demo.sample.SampleApplication:5.3.4]
... 18 common frames omitted
2条答案
按热度按时间3hvapo4f1#
上述问题的解决方案是将build args“-enable url protocols=http”添加到本机映像maven插件中,如下所示。
文件参考号:https://www.graalvm.org/reference-manual/native-image/nativeimagemavenplugin/
2skhul332#
或者如果您使用springboot maven插件: