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

232
Visualizações
Spring boot can I replace ResourceHttpRequestHandler with my own implementation?

I am running into this issue since I have an app that has restful services but I need to serve up some static ones too. In this app I also use the EnableSwagger2 annotation. It looks like this class is public and I could subclass it but I am not sure how to configure that. My goal is to override this line so I can have control over 404s.

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

0

So I finally did do this and it worked successfully for me. The config got me for a bit but here it is. Say you subclass ResourceHttpRequestHandler with one named CustomResourceHandler. In my Application.java this wired it up properly:

@Bean
public ResourceHttpRequestHandler resourceHttpRequestHandler() {
    ResourceHttpRequestHandler requestHandler = new CustomResourceHandler();
    requestHandler.setLocations(Arrays.<Resource>asList(applicationContext.getResource("/")));
    return requestHandler;
}

@Bean
public SimpleUrlHandlerMapping sampleServletMapping(){
    SimpleUrlHandlerMapping mapping = new SimpleUrlHandlerMapping();
    mapping.setOrder(Integer.MAX_VALUE - 2);
    Properties urlProperties = new Properties();
    urlProperties.put("/**", "resourceHttpRequestHandler");
    mapping.setMappings(urlProperties);
    return mapping;
}

@Autowired
ApplicationContext applicationContext;
  • This Answer helped me with the proper config of the mapper.
  • This Answer about context helped me get the locations set properly in my handler. I was setting them a different way but it wasn't working 100% properly for all my resources
about 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