'Resources are called from /appName but from root

I'm usign spring boot. When I deploy my app under a AWS balancer, the app is calling some resources from myDir/myAppName. But the style resources are called from root, like myDir/.

E.g. myDir/myAppName/index.html is accesible for loadBalancer. But myDir/myStilesheet.css isn't accesible.

How can I set that resources (css, etc) under myDir/myAppName?

Thanks in advance!



Solution 1:[1]

You can implement the WebMvcConfigurer interface and override the void addResourceHandlers(final ResourceHandlerRegistry registry) method.

@Configuration
public class MvcConfig implements WebMvcConfigurer {

@Override
public void addResourceHandlers(final ResourceHandlerRegistry registry) {
    registry.addResourceHandler("myDir/myAppName/myStilesheet.css")
        .addResourceLocations("classpath:/resources/static/css/myStilesheet.css");
}}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Alex