Java 字符串启动:UriComponentsBuilder toString

Java 字符串启动:UriComponentsBuilder toString,java,spring,spring-boot,Java,Spring,Spring Boot,我遇到了一个问题,我想它必须很容易解决,但我一直坚持下去 这是我的代码片段: String url = UriComponentsBuilder.fromPath("http://localhost") .build().toUriString(); url的值为: http:/localhost 如您所见,://替换为:// 关于如何解决这个问题,你有什么想法吗?来自路径的将只采用类似/API/student的API或资源路径。但它并不像您的情况那样使用整个url。一种选择是 Ur

我遇到了一个问题,我想它必须很容易解决,但我一直坚持下去

这是我的代码片段:

String url = UriComponentsBuilder.fromPath("http://localhost")
    .build().toUriString();
url
的值为:

http:/localhost
如您所见,
://
替换为
://


关于如何解决这个问题,你有什么想法吗?

来自路径的
将只采用类似
/API/student
的API或资源路径。但它并不像您的情况那样使用整个url。一种选择是

UriComponentsBuilder.fromUriString("http://localhost")
                .build().toUriString();
或者也可以使用

UriComponentsBuilder.newInstance().scheme("http").host("localhost").build().toString();