Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

160
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!