Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

267
Visualizações
How do I change the server name in the links in a Spring RepositoryRestResource?

I've got a simple RepositoryRestResource based off of the guides on spring.io

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

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

}

This does indeed work, as my REST client returns

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

But my question is, where does the http://127.0.0.1:8080 part of the _links come from and how can I change it? When my application goes to production (or any of my environments, like local or dev), I'd rather be able to see something like http://api.mydomain.com.

If it matters, I'm compiling my program with mvn package and running it as a standalone jar on the server.

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

The host and port of your URL are figured out by using HttpServletRequest#getRequestURL (or getRequestURI). So it will always reflect the host and port used by the client when performing the request.

Once you deploy that as api.yourdomain.com, this is what you'll get in the link URLs.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda