[Spring + Bootstrap] No mapping found for HTTP request with URI error while using webjars.

Asked 2 years ago, Updated 2 years ago, 58 views

Hello, everyone I'm practicing making a website with bootstrap and spring We need the help of masters in the face of errors.

I received the webjars library by maven.

And I made you refer to the library file of webjars in the HTML file as below.

-- pageTyWebsite.html --

  <link rel="stylesheet" href="/webjars/bootstrap/3.3.4/dist/css/bootstrap.min.css">
  <script src="/webjars/jquery/2.1.3/dist/jquery.min.js"></script>
  <script src="/webjars/bootstrap/3.3.4/dist/js/bootstrap.min.js"></script>

However, if you turn the server around, the error occurs as shown below and it cannot be applied.

WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/webjars/jquery/2.1.3/dist/jquery.min.js] in DispatcherServlet with name 'appServlet' WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/webjars/bootstrap/3.3.4/dist/js/bootstrap.min.js] in DispatcherServlet with name 'appServlet' WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/webjars/bootstrap/3.3.4/dist/css/bootstrap.min.css] in DispatcherServlet with name 'appServlet' WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/webjars/bootstrap/3.3.4/dist/js/bootstrap.min.js] in DispatcherServlet with name 'appServlet'

If you know the solution, please do. Thank you Below are the web.xml file and servlet-context.xml file that I set up, and the method of controller.

-- web.xml --

  <servlet-mapping> 
    <servlet-name>appServlet</servlet-name>
    <url-pattern>*.do</url-pattern>
  </servlet-mapping>

-- servlet-context.xml --

  <resources mapping="/resources/**" location="/resources/" />
  <resources mapping="/webjars/**" location="/webjars/" />
  <resources mapping="/css/**" location="/css/"/>
  <resources mapping="/img/**" location="/img/"/>
  <resources mapping="/js/**" location="/js/"/>

-- controller.java --

  @RequestMapping("pageSpringFwBoard.do")
   public String pageSpringFwBoard(){
           return "pageTyWebsite"; 
   }

spring-boot bootstrap maven

2022-09-22 20:57

2 Answers

The webjars folder must have bootstrap, jquery, and so on under the webapp directory of the project. If not, the error you asked is normal.

If there are files in the jar file, try the path as follows. If the relevant CSS/JS etc. is in META-INF/resources/webjars/ in webjars.

<resources mapping="/webjars/**" location="classpath:/META-INF/resources/webjars/" />

If not, try the following:

-- servlet-context.xml --

  <beans:bean class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping" />
  <!-- The start tag or the current wrap must have xmlns:beans="http://www.springframework.org/schema/beans" declared. -->
  <resources mapping="/resources/**" location="/resources/" />
  <resources mapping="/webjars/**" location="/webjars/" />
  <resources mapping="/css/**" location="/css/"/>
  <resources mapping="/img/**" location="/img/"/>
  <resources mapping="/js/**" location="/js/"/>

Try adding a handler yourself as above.

Alternatively, if mvc xmlns (xmlns:mvc="http://www.springframework.org/schema/mvc") is declared, replace the tag with the following:

  <mvc:resources mapping="/resources/**" location="/resources/" />
  <mvc:resources mapping="/webjars/**" location="/webjars/" />
  <mvc:resources mapping="/css/**" location="/css/"/>
  <mvc:resources mapping="/img/**" location="/img/"/>
  <mvc:resources mapping="/js/**" location="/js/"/>


2022-09-22 20:57

I used to smell the same... I couldn't find him because the bootstrap version I declared in pom.xml was different from the one I put in the js code

Check it out

For example,

<script src="/webjars/bootstrap/3.3.4/dist/js/bootstrap.min.js"></script>

If you've declared it like this,

Also in foam.xml

<dependency>
   <groupId>org.webjars.bower</groupId>
   <artifactId>bootstrap</artifactId>
   <version>3.3.4</version>
</dependency>

The version is like the one above It has to be declared


2022-09-22 20:57

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.