當(dāng)前位置:
首頁 >
前端技术
> javascript
>内容正文
javascript
SpringMVC-DispatcherServlet配置(Spring-servlet.xml)
生活随笔
收集整理的這篇文章主要介紹了
SpringMVC-DispatcherServlet配置(Spring-servlet.xml)
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
Spring-servlet.xml
掃描指定的包中的類上的注解,常用的注解有:
@Controller 聲明Action組件
@Service??? 聲明Service組件??? @Service("myMovieLister")?
@Repository 聲明Dao組件
@Component?? 泛指組件, 當(dāng)不好歸類時(shí).?
@RequestMapping("/menu")? 請(qǐng)求映射
@Resource? 用于注入,( j2ee提供的 ) 默認(rèn)按名稱裝配,@Resource(name="beanName")?
@Autowired 用于注入,(srping提供的) 默認(rèn)按類型裝配?
@Transactional( rollbackFor={Exception.class}) 事務(wù)管理
@ResponseBody
@Scope("prototype")?? 設(shè)定bean的作用域
匹配URL? /resources/**? 的URL被當(dāng)做靜態(tài)資源,由Spring讀出到內(nèi)存中再響應(yīng)http。
或直接使用默認(rèn)的Servlet來響應(yīng)靜態(tài)文件。
<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/beans9 http://www.springframework.org/schema/beans/spring-beans.xsd 10 http://www.springframework.org/schema/context 11 http://www.springframework.org/schema/context/spring-context.xsd 12 http://www.springframework.org/schema/mvc 13 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 <!--添加訪問靜態(tài)資源的功能 --> 21 <mvc:resources location="/resources/" mapping="/resources/**"></mvc:resources> 22 </beans>?
God, Grant me the SERENITY, to accept the things I cannot change, COURAGE to change the things I can, and the WISDOM to know the difference.
總結(jié)
以上是生活随笔為你收集整理的SpringMVC-DispatcherServlet配置(Spring-servlet.xml)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: shell重启jar包
- 下一篇: [复变函数]第20堂课 5.4 整函数与