springMvc的配置文件
时间: 2023-06-12 21:03:53 浏览: 69
Spring MVC的配置文件是一个XML文件,通常命名为`springmvc-servlet.xml`,其中包含了Spring MVC的相关配置信息。以下是一个简单的Spring MVC配置文件的示例:
```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.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd">
<!-- 开启注解驱动 -->
<mvc:annotation-driven />
<!-- 扫描控制器 -->
<context:component-scan base-package="com.example.controller" />
<!-- 配置视图解析器 -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/views/" />
<property name="suffix" value=".jsp" />
</bean>
<!-- 静态资源处理 -->
<mvc:resources location="/WEB-INF/resources/" mapping="/resources/**" />
</beans>
```
在配置文件中,我们可以进行如下的配置:
- 开启注解驱动,使得Spring MVC可以自动处理注解标记的控制器和方法。
- 配置扫描控制器的路径,使得Spring MVC能够自动发现控制器。
- 配置视图解析器,用于将视图名称解析为具体的视图文件。
- 配置静态资源处理,使得Spring MVC能够处理静态资源请求。