. Advertisement .
..3..
. Advertisement .
..4..
I meeet the exception java lang illegalargumentexception uri is not absolute as seen in the spring boot below.
2020-10-06 17:15:08.417 ERROR 20534 --- [nio-8080-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is java.lang.IllegalArgumentException: URI is not absolute] with root cause
java.lang.IllegalArgumentException: URI is not absolute
at java.net.URI.toURL(URI.java:1088) ~[na:1.8.0_101]
at org.springframework.http.client.SimpleClientHttpRequestFactory.createRequest(SimpleClientHttpRequestFactory.java:145) ~[spring-web-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.http.client.support.HttpAccessor.createRequest(HttpAccessor.java:124) ~[spring-web-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:735) ~[spring-web-5.2.9.RELEASE.jar:5.2.9.RELEASE]
Please help me find out the cause and solution for it. Thanks.
The cause: When a relative url is used to specify the resource, java lang illegalargumentexception uri is not absolute is thrown. The whole url will be utilized to make the rest call in the spring boot RestTemplate.
Solution:
Solution 1: The relative url must be converted to an absolute url if it is let into the rest call in the RestTemplate. The absolute url will be used by the RestTemplate to locate the resource. The whole url “http:/localhost:8080/student” is being used to execute a rest call with RestTemplate in the example below.
Solution 2:
Use the HTTPRequest object to create a complete url if it is using a relative url inside a rest call that points to the same Tomcat server before passing it to the rest template. The example that follows shows how to build an entire url from a relative url to the same server.
Solution 3:
When using a relative url in a RestTemplate and needing to refer to an external host server, its url can be externalized inside the application.properties files. The relative url can have the properties added, like in the example below.
application.properties
TestController.java