gpt4 book ai didi

java - 如何更改 Spring RepositoryRestResource 链接中的服务器名称?

转载 作者:行者123 更新时间:2023-11-30 02:35:03 25 4
gpt4 key购买 nike

我有一个基于 spring.io 上的指南的简单 RepositoryRestResource

@RepositoryRestResource(collectionResourceRel = "people", path = "people")
public interface PersonRepository extends PagingAndSortingRepository<Person, Long>{

List<Person> findByLastName(@Param("name") String lastName);

}

这确实有效,因为我的 REST 客户端返回了

{
"_links" : {
"people" : {
"href" : "http://127.0.0.1:8080/people{?page,size,sort}",
"templated" : true
},
"profile" : {
"href" : "http://127.0.0.1:8080/profile"
}
}
}

但我的问题是,_linkshttp://127.0.0.1:8080 部分来自哪里以及如何更改它?当我的应用程序投入生产(或我的任何环境,如本地或开发)时,我宁愿能够看到类似 http://api.mydomain.com 的内容。

如果重要的话,我会使用 mvn package 编译我的程序,并将其作为独立的 jar 在服务器上运行。

最佳答案

您的 URL 的主机和端口是通过使用 HttpServletRequest#getRequestURL 计算出来的(或getRequestURI)。所以它总是反射(reflect)客户端在执行请求时使用的主机和端口。

将其部署为 api.yourdomain.com 后,您将在链接 URL 中获得以下内容。

关于java - 如何更改 Spring RepositoryRestResource 链接中的服务器名称?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43308029/

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