0

I have followin project structure..

enter image description here

Now, I want load the static resources from resources/static/resources. I have tried to add following in my mvc configuration without any success.

    registry.addResourceHandler("/**").addResourceLocations("classpath:/static/");
    registry.addResourceHandler("/**").addResourceLocations("classpath:/static/resources/");
registry.addResourceHandler("/resources/**").addResourceLocations("classpath:/static/");
    registry.addResourceHandler("/resources/**").addResourceLocations("classpath:/static/resources/");

I want to access the resource directory under static as

 <script type="text/javascript" src="/resources/scripts/jquery-3.3.1.min.js"></script>

Any help or recommendation appreciated. Thanks.

Also tried following,

    registry.addResourceHandler("/**").addResourceLocations("classpath:/static/");
       registry.addResourceHandler("/**").addResourceLocations("classpath:/static/resources/");
       registry.addResourceHandler("/resources/**").addResourceLocations("classpath:/static/");
       registry.addResourceHandler("/resources/**").addResourceLocations("classpath:/static/resources/");
       registry.addResourceHandler("/resources/**").addResourceLocations("/resources/");
       registry.addResourceHandler("/resources/**").addResourceLocations("/resources/");
       registry.addResourceHandler("/resources/**").addResourceLocations("classpath:/resources/");
       registry.addResourceHandler("/**").addResourceLocations("classpath:/static/");
       registry.addResourceHandler("/resources/**").addResourceLocations("classpath:/static/resources/");
       registry.addResourceHandler("/**").addResourceLocations("classpath:/");
       registry.addResourceHandler("/**").addResourceLocations("classpath:/static/");

registry.addResourceHandler("/**").addResourceLocations("/WEB-INF/classes/static/");
       registry.addResourceHandler("/resources/**").addResourceLocations("/WEB-INF/classes/static/resources/");
       registry.addResourceHandler("/resources/**").addResourceLocations("classpath:/static/resources/");

But does not work.

Prashant
  • 31
  • 7
  • 1
    What templating view are u using? JSP, thymeleaf? and from where in your directory structure you want to access it? – ISlimani Jun 27 '18 at 19:38
  • 1
    Spring Boot serves the static folder by default. Doesn't it work for you? Maybe you override the default Boot behavior. – Evgeni Dimitrov Jun 27 '18 at 20:22
  • @DforTye I am using thymeleaf. I have login.html under resources/template (not under static folder) which uses the script tag I mentioned earlier. – Prashant Jun 28 '18 at 02:56
  • @EvgeniDimitrov Yes. But does not seem to be working while deploying on standalone tomcat. – Prashant Jun 28 '18 at 02:57
  • 1
    @Prashant When you deploy on standalone tomcat your application has a context. In other words the name of your war file is added to the url of the resources. Do you take that in account? – Evgeni Dimitrov Jun 28 '18 at 11:02
  • Yes. the context path is '/' so it should not be a problem. And also while I add registry.addResourceHandler("/**").addResourceLocations("classpath:/"); I am able to access the resource as src="/static/resources/scripts/jquery-3.3.1.min.js" But my requirement is src="/resources/scripts/jquery-3.3.1.min.js" @EvgeniDimitrov – Prashant Jun 28 '18 at 11:22

0 Answers0