2012-08-04 127 views
1


我知道有很多这样的问题在网络上(尤其是在这里),但没有真正帮助我的。我在使用Spring MVC(春季版3.1.0.RELEASE),我想通过URL来访问我的静态数据。
我的包:
-src
- 主
---资源
----公共
内公共我有例如文件的test.xml。
这是我的web.xml获取静态资源的Spring MVC

<context-param> 
     <param-name>contextConfigLocation</param-name> 
     <param-value>/WEB-INF/spring/ApplicationContext.xml</param-value> 
    </context-param> 
<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/ServletContext.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> 

这是我ServletContext.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/public/**" location="/resources/public/" /> 


现在,当我进入这个网址“本地主机:8080/bmark中央/资源/公/测试.XML”我收到了404我试了一下没有上下文根‘本地主机:8080 /资源/公/的test.xml’,也没有得到我的test.xml(也得了404)。我是映射出问题了吗?我失去了一些东西?在此先感谢:)

回答

0

问题可能是静态资源应该是相对于您的web内容 - 所以他们应该在此文件夹中可访问 - src/main/webapp/resources/public而不是src/main/resources