SpringMVC 配置文件详解
2014-03-13 11:36
393 查看
1. 配置web.xml. 启动SpringMVC
SpringMVC 是通过Servlet启动,所以需要在web.xml中配置SpringMVC的Servlet。如下代码示例:
2. applicationContext-mvc.xml(该文件名称可以自定义,但是要和web.xml中名称保持一致)
SpringMVC 是通过Servlet启动,所以需要在web.xml中配置SpringMVC的Servlet。如下代码示例:
<span style="white-space:pre"> </span><servlet> <servlet-name>springServlet</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:spring/applicationContext-mvc.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>springServlet</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping>
2. applicationContext-mvc.xml(该文件名称可以自定义,但是要和web.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: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-4.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd"> <description>Spring MVC Configuration</description> <!-- 加载Properties文件 --> <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="locations"> <list> <value>classpath:config.properties</value> </list> </property> </bean> <!-- 使用Annotation自动注册Bean,只扫描@Controller --> <context:component-scan base-package="cn.tyrone.wallet.controller" use-default-filters="false"> <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/> </context:component-scan> <!-- 定义视图文件解析 --> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="${web.view.prefix}"/> <property name="suffix" value="${web.view.suffix}"/> </bean> <mvc:annotation-driven /> <!-- 静态资源映射 --> <span style="white-space:pre"> </span><mvc:resources mapping="/static/**" location="/static/" cache-period="31536000"/> <!-- 定义无Controller的path<->view直接映射 --> <mvc:view-controller path="/" view-name="redirect:${web.view.index}"/> </beans>
相关文章推荐
- springmvc 配置文件详解
- SpringMVC文件上传的配置实例详解
- SpringMVC深度探险(四) —— SpringMVC核心配置文件详解
- SpringMVC深度探险(四) —— SpringMVC核心配置文件详解
- SpringMVC深度探险(四) —— SpringMVC核心配置文件详解
- SpringMVC深度探险 —— SpringMVC核心配置文件详解
- springmvc配置文件web.xml详解各方总结。
- SpringMVC配置文件详解
- SpringMVC的web.xml配置文件详解
- SpringMVC配置web.xml文件详解(列举常用的配置)
- Spring详解之四:SpringMVC整合Mybatis相关配置文件信息
- (4)SpringMVC核心配置文件详解
- 最基本的springMVC配置文件详解
- springmvc配置文件web.xml详解各方总结。
- springmvc必备jar包分析以及配置文件详解
- SpringMVC深度探险(四) —— SpringMVC核心配置文件详解
- springmvc配置文件web.xml详解各方总结。
- springmvc是 spring的一个组件,他们各自的配置文件详解
- SpringMVC深度探险(四) —— SpringMVC核心配置文件详解
- SpringMVC和Spring的配置文件扫描包详解