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?
Try this :
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry
.addResourceHandler("/client/**")
.addResourceLocations("/client/");
}
<%@ 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>