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

161
Visualizações
Different way to provide static resources with ResourceHandlerRegistry

I have to startup a Angular 1 application with Java backend. I thought to use the same folder structure of a previous one done months before with Angular 1 as frontend and Storngloop as backend.

My frontend web application is composed by this folder structure:

src
  |
  main
    |
    webapp
        |
        client

Inside app folder ich habe the whole application composed by subfolders which inside other .css, .js, .html files (in every folder ther's a part of my application. By instance: login form folder, with its .css, .html and .js files inside and so on...).

Something like:

client
      |
      login
          |
          login.html
          |
          login.css
          |
          login.js
      stuff
          |
          stuff.html
          |
          stuff.css
          |
          stuff.js

and in the index.html I would do (2):

<link rel="stylesheet" href="client/login/login.css">
...
<script src="client/login/login.js"></script>

So I thought to configure my ResourceHandlerRegistry as follows (1):

@Configuration
@EnableWebMvc
@ComponentScan(basePackages = "my.package")
public class Configurations extends WebMvcConfigurerAdapter {

    @Override
    public void configureViewResolvers(ViewResolverRegistry registry) {
        InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
        viewResolver.setViewClass(JstlView.class);

        viewResolver.setPrefix("/client/");
        viewResolver.setSuffix(".html");

        registry.viewResolver(viewResolver);
    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        //resources locations
        registry.addResourceHandler("client/**").addResourceLocations("/client/**");
    }

}

but when in my index.html file I try to include any of .js or .css files I got 404 from the server for each resource included in point (2)... as I expected... I had to do this (3):

registry.addResourceHandler("client/**").addResourceLocations("/client/", "/client/login/", "/client/stuff/", //ecc... ecc...);

declaring every single path to every resource of my frontend verithing works perfectly! Really, I know that's ugly!

Can be done something like the (1) without declaring EVERY SINGLE RESOURCE PATH?

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

0

Try this :

  1. Config :
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
    registry
        .addResourceHandler("/client/**")
        .addResourceLocations("/client/");
}
  1. Jsps :
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

<link rel="stylesheet" href="<c:url value="/client/login/login.css" />">
<script src="<c:url value="/client/login/login.js" />"></script>
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