webjars bloc 我所有的页面(spring mvc 和 maven 项目)
webjars bloc all my pages (spring mvc and maven project)
我在 spring mvc 中使用 webjars,其配置与 webjars 文档相同,但是当我添加这一行时,所有页面都出现 404 错误:
mvc:resources mapping="/webjars/**" location="/webjars/"
请问有什么问题??
来自 pom.xml 的部分:
<!-- webJars -->
<dependency>
<groupId>org.webjars</groupId>
<artifactId>materializecss</artifactId>
<version>0.97.5</version>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>jquery</artifactId>
<version>2.2.2</version>
</dependency>
<!-- spring -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>4.2.5.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>4.2.5.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.2.5.RELEASE</version>
</dependency>
来自调度员的一部分-servlet.xml
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd">
<context:component-scan base-package="controllers" />
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/views/" />
<property name="suffix" value=".jsp" />
</bean>
<mvc:resources mapping="/webjars/**" location="/webjars/"/>
部分来自 web.xml
<web-app>
<display-name>Archetype Created Web Application</display-name>
<!-- The front controller of this Spring Web application, responsible for handling all application requests -->
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<!-- Map all requests to the DispatcherServlet for handling -->
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<!-- needed for ContextLoaderListener -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/dispatcher-servlet.xml</param-value>
</context-param>
<!-- Bootstraps the root web application context before servlet initialization -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
和 jsp:
<head>
<title>log in</title>
<link rel="stylesheet" href="/webjars/materialize/0.97.5/css/materialize.min.css">
</head>
<body>
<div class="row">
<form class="col s12">
<div class="row">
<div class="input-field col s6">
<input placeholder="Placeholder" id="first_name" type="text" class="validate">
<label for="first_name">First Name</label>
</div>
</div>
</form>
</div>
<!-- Compiled and minified JavaScript -->
<script src="webjars/materialize/0.97.5/js/materialize.min.js"></script>
<script src="webjars/jquery/2.2.2/jquery.min.js"></script>
</body>
标签 mvc:annotation-driven 从配置文件中弄乱了有关它的更多信息,请参阅:
Whosebug :
What does <mvc:annotation-driven /> do?
spring docs :
http://docs.spring.io/spring/docs/current/spring-framework-reference/html/mvc.html
我在 spring mvc 中使用 webjars,其配置与 webjars 文档相同,但是当我添加这一行时,所有页面都出现 404 错误:
mvc:resources mapping="/webjars/**" location="/webjars/"
请问有什么问题??
来自 pom.xml 的部分:
<!-- webJars -->
<dependency>
<groupId>org.webjars</groupId>
<artifactId>materializecss</artifactId>
<version>0.97.5</version>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>jquery</artifactId>
<version>2.2.2</version>
</dependency>
<!-- spring -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>4.2.5.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>4.2.5.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.2.5.RELEASE</version>
</dependency>
来自调度员的一部分-servlet.xml
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd">
<context:component-scan base-package="controllers" />
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/views/" />
<property name="suffix" value=".jsp" />
</bean>
<mvc:resources mapping="/webjars/**" location="/webjars/"/>
部分来自 web.xml
<web-app>
<display-name>Archetype Created Web Application</display-name>
<!-- The front controller of this Spring Web application, responsible for handling all application requests -->
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<!-- Map all requests to the DispatcherServlet for handling -->
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<!-- needed for ContextLoaderListener -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/dispatcher-servlet.xml</param-value>
</context-param>
<!-- Bootstraps the root web application context before servlet initialization -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
和 jsp:
<head>
<title>log in</title>
<link rel="stylesheet" href="/webjars/materialize/0.97.5/css/materialize.min.css">
</head>
<body>
<div class="row">
<form class="col s12">
<div class="row">
<div class="input-field col s6">
<input placeholder="Placeholder" id="first_name" type="text" class="validate">
<label for="first_name">First Name</label>
</div>
</div>
</form>
</div>
<!-- Compiled and minified JavaScript -->
<script src="webjars/materialize/0.97.5/js/materialize.min.js"></script>
<script src="webjars/jquery/2.2.2/jquery.min.js"></script>
</body>
标签 mvc:annotation-driven 从配置文件中弄乱了有关它的更多信息,请参阅:
Whosebug : What does <mvc:annotation-driven /> do?
spring docs : http://docs.spring.io/spring/docs/current/spring-framework-reference/html/mvc.html