zoukankan      html  css  js  c++  java
  • springmvc基础篇—拆分配置文件

    一般来讲,在企业实际项目中通常会将配置文件设置为两个:spring-mvc.xml、beans.xml,各自管各自的内容,方便管理。

    一、在src下增加如下配置文件:

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:mvc="http://www.springframework.org/schema/mvc"
        xmlns:context="http://www.springframework.org/schema/context"
        xmlns:aop="http://www.springframework.org/schema/aop" 
        xmlns:tx="http://www.springframework.org/schema/tx"
        xsi:schemaLocation="http://www.springframework.org/schema/beans 
                            http://www.springframework.org/schema/beans/spring-beans-3.2.xsd 
                            http://www.springframework.org/schema/mvc 
                            http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd 
                            http://www.springframework.org/schema/context 
                            http://www.springframework.org/schema/context/spring-context-3.2.xsd
                            http://www.springframework.org/schema/aop 
                            http://www.springframework.org/schema/aop/spring-aop-3.2.xsd 
                            http://www.springframework.org/schema/tx 
                            http://www.springframework.org/schema/tx/spring-tx-3.2.xsd ">
        
        <!-- 自动扫描 -->
        <context:component-scan base-package="cn.cfs.springmvc.service,cn.cfs.springmvc.dao"/>
    
    </beans>
    beans.xml

    二、配置web.xml

        <!-- 将beans配置文件load到spring-mvc配置文件中 -->
         <context-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>classpath:beans.xml</param-value>
        </context-param>
        <listener>
            <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
        </listener> 

    三、spring-mvc.xml中自动包扫描只保留controller的包扫描。

  • 相关阅读:
    微软Enterprise Library 4.0将支持依赖注入
    javascript cookies 存、取、删除实例
    动态调用 WebService(转)
    IE缓存是什么?cookies是什么?
    序列化
    PKI
    ASP.NET的(HttpModule,HttpHandler)(转)
    PKI基础 二.PKI基础5.数字证书及应用(转,一个加密解密的全过程)
    AOP技术基础(转)
    getChildByName()与getChildAt()效率比较
  • 原文地址:https://www.cnblogs.com/mycifeng/p/6367544.html
Copyright © 2011-2022 走看看