首页 > 代码库 > Spring配置文件

Spring配置文件

applicationContext.xml

<mvc:resources mapping="" location="">

主要用来进行静态资源的访问

首先使用spring mvc需要配置其使用的servlet.在web.xml中: 

Java代码  技术分享
    1. <servlet>  
    2.     <servlet-name>springMVC</servlet-name>  
    3.     <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>  
    4.     <load-on-startup>1</load-on-startup>  
    5.     </servlet>  
    6.   
    7.     <servlet-mapping>  
    8.         <servlet-name>springMVC</servlet-name>  
    9.         <url-pattern>/</url-pattern>  
    10.     </servlet-mapping>  

springMVclanjie了所有请求

<servlet-mapping> 
<servlet-name>springMVC</servlet-name> 
<url-pattern>/</url-pattern> 
</servlet-mapping>

会影响到静态资源访问。

 

  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <beans xmlns="http://www.springframework.org/schema/beans"    
  3.     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"    
  4.     xmlns:mvc="http://www.springframework.org/schema/mvc"  
  5.     xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd     
  6.     http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">     
  7.   
  8.     <mvc:resources mapping="/javascript/**" location="/static_resources/javascript/"/>  
  9.     <mvc:resources mapping="/styles/**" location="/static_resources/css/"/>  
  10.     <mvc:resources mapping="/images/**" location="/static_resources/images/"/>  
  11.     <mvc:default-servlet-handler />  
  12.       
  13.       
  14.     <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">  
  15.         <property name="prefix" value=http://www.mamicode.com/"/WEB-INF/views/"/>  
  16.         <property name="suffix" value=http://www.mamicode.com/".jsp"/>  
  17.     </bean>  
  18.   
  19. </beans>  

 

 

 

 

 

 

 

 

Spring配置文件