我无法在我的 SPring MVC 3.2.6 + Tomcat7 项目中使用 font-awesome.4.4.0 webjars。但是我可以通过 CDN 使用,尽管我不想要依赖项。
pom.xml
<dependency>
<groupId>org.webjars</groupId>
<artifactId>font-awesome</artifactId>
<version>4.4.0</version>
</dependency>
在 servlet-config.xml 我有以下代码,
<mvc:resources location="pdfs" mapping="/pdfs/**" />
<mvc:resources mapping="/resources/**" location="/resources/theme1/"/>
<mvc:resources mapping="/webjars/**" location="classpath:/META-INF/resources/webjars/"/>
在我的 login.jsp 中,我试图访问 font-awesome.css,如下所示,
<link href="/webjars/font-awesome/4.4.0/css/font-awesome.css" rel="stylesheet" />
(或者)
<link href="${pageContext.request.contextPath}/webjars/font-awesome/4.4.0/css/font-awesome.css" rel="stylesheet" />
(或者)
<link href="<c:url value='/webjars/font-awesome/4.4.0/css/font-awesome.css' />" rel="stylesheet">
我按照下面的链接,但没有运气,
我也尝试过使用 webcater,
<dependency>
<groupId>org.webjars</groupId>
<artifactId>webjars-locator</artifactId>
<version>0.1</version>
在 servlet-config.xml 和我的 login.jsp 中提供了资源,我使用下面的方法访问该文件,
<link rel='stylesheet' href='<%= org.webjars.AssetLocator.getWebJarPath("css/font-awesome.css") %>'>
请找到以下 web.xml,
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/config/security-config.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>taskManagementServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/config/servlet-config.xml</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>taskManagementServlet</servlet-name>
<url-pattern>*.html</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>taskManagementServlet</servlet-name>
<url-pattern>*.json</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>taskManagementServlet</servlet-name>
<url-pattern>/pdfs/**</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>1</session-timeout>
</session-config>
</web-app>
请指导我纠正错误。