[英]Cannot load static resources when using web fragments and spring
I have a main spring hello webapp, which has an include in the web.xml to include a web-fragment. 我有一个主要的spring hello webapp,它在web.xml中包含一个web片段。 I can't seem to get access tot he static resources in the jar, im using tomcat 7, servlet 3, Spring 3.2.3.RELEASE
我似乎无法访问jar中的静态资源,即时通讯使用的是tomcat 7,servlet 3,Spring 3.2.3。
and my jar structure is test.jar->META-INF->test.css 我的罐子结构是test.jar-> META-INF-> test.css
but when i load the app, the url: 但是当我加载应用程序时,URL:
http://localhost:8686/spring-fragment-test/test.css http:// localhost:8686 / spring-fragment-test / test.css
does not seem to work, keep getting 404 似乎无效,请继续获取404
i have configured as following: 我已经配置如下:
Spring.xml in the main app 主应用中的Spring.xml
<!-- Enables the Spring MVC @Controller programming model -->
<annotation-driven />
<!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory -->
<resources mapping="/resources/**" location="/resources/" />
<!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/views directory -->
<beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<beans:property name="prefix" value="/WEB-INF/views/" />
<beans:property name="suffix" value=".jsp" />
</beans:bean>
<context:component-scan base-package="com.fragments" />
with the web.xml 与web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
<!-- The definition of the Root Spring Container shared by all Servlets and Filters -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/root-context.xml</param-value>
</context-param>
<!-- Creates the Spring Container shared by all Servlets and Filters -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- Processes application requests -->
<servlet>
<servlet-name>appServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>appServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<absolute-ordering>
<name>SampleFragment</name>
</absolute-ordering>
</web-app>
my other fragemt jar has the following xml in the meta-inf 我的另一个fragemt jar在meta-inf中具有以下xml
<?xml version="1.0" encoding="UTF-8"?>
<web-fragment id="WebFragment_ID" version="3.0" 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-fragment_3_0.xsd">
<display-name>SampleFragment</display-name>
<name>SampleFragment</name>
</web-fragment>
Since you are putting the location "/resources/" in the xml 由于您将位置“ / resources /”放置在xml中
<mvc:resources mapping="/resources/**" location="/resources/" />
You have to put your css file in the section 您必须将css文件放在该部分中
Web-Content/resources/(css file) 网页内容/资源/(css文件)
You can now access the file by writing 您现在可以通过写入来访问文件
http://loclahost:8080/spring/resources/main.css http:// loclahost:8080 / spring / resources / main.css
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.