SpringMVC与Spring整合

一、框架整合

  • 把SpringMVC和Spring框架整合的目的就是为了使得框架分工明确。
  • SpringMVC的配置文件用来配置和网站转发逻辑以及网站功能(视图解析器、文件上传解析器、支持Ajax等等)。
  • Spring配置文件用来配置与业务有关的功能(事务控制,数据源,等等)。

二、SpringMVC和Spring分容器

在这里插入图片描述
springMVC.xml文件中可以引入另一个配置文件,但是这样服务器一启动,只有一个IOC容器,即合并以后的大IOC容器。

<import resource="spring.xml">import>

为了实现分容器

spring.xml

    
    <context:component-scan base-package="*" use-default-filters="false">
        
        <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller">context:exclude-filter>
        <context:exclude-filter type="annotation" expression="org.springframework.web.bind.annotation.ControllerAdvice">context:exclude-filter>
    context:component-scan>

springMVC.xml

    <context:component-scan base-package="controller" use-default-filters="false">
        
        <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller">context:include-filter>
        
        <context:include-filter type="annotation" expression="org.springframework.web.bind.annotation.ControllerAdvice">context:include-filter>
    context:component-scan>

你可能感兴趣的:(SpringMVC,Spring框架,SpringMVC,Spring)