springmvc servlet.xml

在使用注解的情况下,系统启动时会被自动扫描,并添加到bean工厂中,省去了配置文件中写bean定义

1.启动mvc注解驱动

<mvc:annotation-driven />

2.组件扫描

<context:component-scan base-package="....">

在xml配置了这个标签后,spring可以自动去扫描base-package下面或者子包下面的java文件,如果扫描到有@Component @Controller @Service等这些注解的类,则把这些类注册为bean,不用在配置文件中配置bean

3.ViewResolver、View映射关系

4.拦截器配置

5.国际化配置

<bean id ="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">...

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:util="http://www.springframework.org/schema/util" xmlns:mvc="http://www.springframework.org/schema/mvc"
    xsi:schemaLocation="http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd
                           http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
                           http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
                           http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
    <!-- 启动mvc注解驱动 -->
    <mvc:annotation-driven />
    <!-- 注解探测器 -->
    <context:component-scan base-package="spring.ioc.test">
        <context:include-filter type="annotation"
            expression="org.springframework.stereotype.Service" />
    </context:component-scan>
    <!-- viewResolver & view映射关系 -->
    <bean id="viewResolverJSP"
        class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="viewClass"
            value="org.springframework.web.servlet.view.JstlView" />
        <property name="cache" value="false" />
        <property name="prefix" value="/"></property>
        <property name="suffix" value=".jsp"></property>
        <property name="contentType">
            <value>text/html;charset=UTF-8</value>
        </property>
    </bean>
    <!-- 自定义拦截器配置 -->
    <mvc:interceptors>
    <mvc:interceptor>
    <mvc:mapping path="/hhtest/*"/>
    <bean class="spring.ioc.interceptor.MyInterceptor"></bean>
    </mvc:interceptor>
    </mvc:interceptors>
</beans>

 

posted on 2015-03-12 16:11  yingyi  阅读(282)  评论(0)    收藏  举报