SpringMVC-DispatcherServlet配置(Spring-servlet.xml)
来源:互联网 发布:剑三捏脸数据成女网盘 编辑:程序博客网 时间:2024/06/06 12:24
接上一篇:web.xml
Spring-servlet.xml
- <context:component-scan base-package="com.spring.mvc.controller"/>
扫描指定的包中的类上的注解,常用的注解有:
@Controller 声明Action组件
@Service 声明Service组件 @Service("myMovieLister")
@Repository 声明Dao组件
@Component 泛指组件, 当不好归类时.
@RequestMapping("/menu") 请求映射
@Resource 用于注入,( j2ee提供的 ) 默认按名称装配,@Resource(name="beanName")
@Autowired 用于注入,(srping提供的) 默认按类型装配
@Transactional( rollbackFor={Exception.class}) 事务管理
@ResponseBody
@Scope("prototype") 设定bean的作用域 - <mvc:annotation-driven /> 是一种简写形式,完全可以手动配置替代这种简写形式,简写形式可以让初学都快速应用默认配置方案。<mvc:annotation-driven /> 会自动注册DefaultAnnotationHandlerMapping与AnnotationMethodHandlerAdapter 两个bean,是spring MVC为@Controllers分发请求所必须的。
- 视图解析类,使用普通bean的配置方式:
1 <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">2 <property name="prefix" value="/WEB-INF/views/"></property>3 <property name="suffix" value=".jsp"></property>4 <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"></property>5 </bean>
- 添加静态资源访问的支持:
1 <mvc:resources location="/resources/" mapping="/resources/**"></mvc:resources>
匹配URL /resources/** 的URL被当做静态资源,由Spring读出到内存中再响应http。
或直接使用默认的Servlet来响应静态文件。
<mvc:default-servlet-handler/>
示例:
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 xmlns:p="http://www.springframework.org/schema/p" 6 xmlns:context="http://www.springframework.org/schema/context" 7 xsi:schemaLocation=" 8 http://www.springframework.org/schema/beans 9 http://www.springframework.org/schema/beans/spring-beans.xsd10 http://www.springframework.org/schema/context11 http://www.springframework.org/schema/context/spring-context.xsd12 http://www.springframework.org/schema/mvc13 http://www.springframework.org/schema/mvc/spring-mvc.xsd">14 <context:component-scan base-package="com.spring.mvc.controller"/>15 <mvc:annotation-driven/>16 <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">17 <property name="prefix" value="/WEB-INF/views/"></property>18 <property name="suffix" value=".jsp"></property>19 </bean>20 <!--添加访问静态资源的功能 -->21 <mvc:resources location="/resources/" mapping="/resources/**"></mvc:resources>22 </beans>
0 0
- SpringMVC-DispatcherServlet配置(Spring-servlet.xml)
- SpringMVC-DispatcherServlet配置(Spring-servlet.xml)
- Spring的dispatcherServlet-servlet.xml配置文档
- Spring Mvc DispatcherServlet-servlet.xml
- springmvc web.xml spring-servlet.xml 配置
- SpringMVC-基础篇-DispatcherServlet-servlet.xml
- SpringMVC-提高篇-DispatcherServlet-servlet.xml
- springMVC spring-servlet.xml配置详细
- Spring配置之springmvc-servlet.xml
- springMVC-servlet.xml 配置
- SpringMVC servlet.xml配置
- springMvc 配置 controller 配置 spring-dispatcher-servlet.xml
- dispatcherServlet-servlet.xml 详细信息
- spring-servlet.xml配置
- springMVC 多 dispatcherServlet 配置
- SpringMVC之DispatcherServlet配置。
- SpringMVC前端调度器 DispatcherServlet web.xml配置
- SpringMVC-DispatcherServlet工作流程及web.xml配置
- SpringMVC配置
- ubuntu下如何修改端口号
- Git学习笔记与IntelliJ IDEA整合
- this关键字
- SpringMVC-DispatcherServlet工作流程及web.xml配置
- SpringMVC-DispatcherServlet配置(Spring-servlet.xml)
- Oracle查询优化-插入、更新与删除
- Oracle查询优化-使用字符串
- 特征工程
- 不定长数组的输入问题C/C++实现
- SpringMVC-Controller
- linux驱动模型开发——linux platform总线机制讲解与实例开发
- Java基础-JDBC访问数据库
- ActiveMQ笔记(2):基于ZooKeeper的HA方案