【发布时间】:2021-03-29 15:45:20
【问题描述】:
我有一个 spring 原生应用程序,它可以对另一个服务进行 http 调用。 我使用本机映像 maven 插件(mvn -Pnative-image 包)编译了该服务。当我的应用程序尝试进行 http 调用时,我看到了这条消息,“支持 URL 协议 http,但默认情况下不启用。必须通过将 --enable-url-protocols=http 选项添加到 native-image 来启用它命令。”
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
【问题讨论】:
标签: spring http native graalvm