springmvc resources 读取配置静态文件目录

annomvc-servlet.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
	xmlns:context="http://www.springframework.org/schema/context"
	xmlns:mvc="http://www.springframework.org/schema/mvc"
	xsi:schemaLocation="http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    http://www.springframework.org/schema/context 
    http://www.springframework.org/schema/context/spring-context-3.0.xsd  
    http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">

	<span style="color:#ff0000;"><bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
		<property name="locations">
			<list>
				<value>classpath*:system.properties</value>
			</list>
		</property>
	</bean>
	
	<context:component-scan base-package="xxxx.xxx" />
	
	<!-- 静态资源映射配置,目前支持	*.json,*.css,*.js,*.ico,*.swf,*.gif,*.jpeg,*.bmp,*.jpg,*.png
		 若需添加,请在web.xml里面配置相应路径 -->
	<!-- 开发环境:路径由开发者自行修改env.properties里面的nas.root.dir -->
	<mvc:resources location="file:${nas.root.dir}/common/" mapping="/common/**"/>
	<mvc:resources location="file:${nas.root.dir}/pages/" mapping="/pages/**" /></span>
	
	<bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" />

	<!-- 配置json -->
	<bean id="messageConverters" class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter" />
	<!-- 启动 Spring MVC 的注解功能,完成请求和注解 POJO 的映射 -->
	<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
		<property name="messageConverters" ref="messageConverters" />
	</bean>

	<!-- 配置试图解析 -->
	<bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
		<property name="contentNegotiationManager">
	     <bean class="org.springframework.web.accept.ContentNegotiationManagerFactoryBean">
	     	<property name="mediaTypes">
	     		<props>
	     			<prop key="atom">application/atom+xml</prop>
	     			<prop key="html">text/html</prop>
	     			<prop key="json">application/json</prop>
	     		</props>
		</property>
	     </bean>
		</property>
		<property name="viewResolvers">
			<list>
				<!-- 对模型视图名称的解析,即在模型视图名称添加前后缀 -->
				<bean class="org.springframework.web.servlet.view.BeanNameViewResolver" />
			</list>
		</property>
	</bean>
	
	<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" p:prefix="/pages/" p:suffix=".jsp" />
	
	<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" p:prefix="/pages/" p:suffix=".html" />
		
</beans>


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_2_5.xsd"
	version="2.5">
	...
	<servlet>
		<servlet-name>annomvc</servlet-name>
		<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
		<load-on-startup>2</load-on-startup>
	</servlet>
	<servlet-mapping>
		<servlet-name>annomvc</servlet-name>
		<url-pattern>*.shtml</url-pattern>
		<url-pattern>*.do</url-pattern>
		<url-pattern>/external/investinfosync</url-pattern>
		<!-- 本地静态资源映射配置,与以下相同后缀的请求地址需要注意,千万不能重复 -->
        <url-pattern>*.json</url-pattern>
		<url-pattern>*.css</url-pattern>
		<url-pattern>*.js</url-pattern>
		<url-pattern>*.ico</url-pattern>
        <url-pattern>*.swf</url-pattern>
        <url-pattern>*.gif</url-pattern>
        <url-pattern>*.jpeg</url-pattern>
        <url-pattern>*.bmp</url-pattern>
        <url-pattern>*.jpg</url-pattern>
        <url-pattern>*.png</url-pattern>
	</servlet-mapping>
	...
</web-app>



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值