Webjars In Spring Download - Javascript not loading

I am trying to add jQuery to my boot application using Webjars. I got inspiration from this tutorial: http://spring.io/blog/2014/01/03/utilizing-webjars-in-spring-boot

In my pom.xml, I added:

<dependency> <groupId>org.webjars</groupId> <artifactId>jquery</artifactId> <version>2.1.1</version> </dependency> 

In my html file (using ThymeLeaf for my template engine - not sure if it matters) I have the following:

 <script src="webjars/jquery/2.1.1/jquery.min.js"></script> 

The file does not load. I tried both src = "webjars ...." and src = "/ webjars ...".

I see a jar in the Maven dependencies listed in my project. When I research this jar, I see META-INF / resources / webjars / jquery / 2.1.1 / jquery.min.js. Based on how I understand that Boot is looking for resources, I think it should find this.

Does anyone see this behavior? Any tips on how to deal with this problem?

+5
source share
1 answer

This works for me:

 <script src="/webjars/jquery/2.1.1/jquery.min.js" type="text/javascript"></script> 

Are you sure this is really on the way to classes at runtime? Do you use an application with an outline (ie Do not serve assets from "/")?

+5
source

Source: https://habr.com/ru/post/1202900/


All Articles