Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

154
Vistas
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?

about 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

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>
about 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda