當前位置:
首頁 >
前端技术
> javascript
>内容正文
javascript
SpringMVC-DispatcherServlet配置(Spring-servlet.xml)
生活随笔
收集整理的這篇文章主要介紹了
SpringMVC-DispatcherServlet配置(Spring-servlet.xml)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
Spring-servlet.xml
掃描指定的包中的類上的注解,常用的注解有:
@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的作用域
匹配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/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 <!--添加訪問靜態資源的功能 --> 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.
總結
以上是生活随笔為你收集整理的SpringMVC-DispatcherServlet配置(Spring-servlet.xml)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: shell重启jar包
- 下一篇: gradle idea java ssm