springmvc配置文件
时间: 2023-07-11 13:05:21 浏览: 41
以下是一个简单的Spring MVC配置文件示例:
```xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
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">
<context:component-scan base-package="com.example.controller"/>
<mvc:annotation-driven/>
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/views/"/>
<property name="suffix" value=".jsp"/>
</bean>
</beans>
```
这个配置文件中包含了以下内容:
- `context:component-scan` 元素用于扫描指定包中的组件,例如控制器。
- `mvc:annotation-driven` 元素用于启用Spring MVC的注解驱动。
- `InternalResourceViewResolver` bean 用于指定视图解析器,它将逻辑视图名映射为物理视图(例如JSP文件)的路径。