分享

Spring Web 中模块化配置文件的加载

 藏经阁_苍穹 2015-11-20
Spring中配置文件的读取:
在分层的软件体系结构中,有数据访问层,业务逻辑层,表现层,安全层。实现各层功能的一系列Bean均需要进行配置.
如果将整个应用程序的Bean都配置在applicationContext.xml一个文件中,这将使维护工作相当困难。
所以可以将各层的bean分别配置在各层的xml配置文件中:
比如一个onlineStore应用中,可以创建如下xml配置文件:
onlineStore-servlet.xml---------------配置Web层组件(Controller,ViewResolver,HandlerMapping等)
onlineStore-service.xml---------------服务层Bean
onlineStore-data.xml-----------------数据访问层
onlineStore-security.xml-------------安全控制层Bean

然后在web.xml中配置一个Context Loader
<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

此外还要告诉这个ContextLoaderListener去哪里找Spring 的配置文件:
默认是找/WEB-INF/applicationContext.xml

<context-param>
 <param-name>contextConfigLocation</param-name>
 <param-value>
        /WEB-INF/onlineStore-service.xml
        /WEB-INF/onlineStore-security.xml
        /WEB-INF/onlineStore-data.xml
 </param-value>

onlineStore-servlet.xml未配置是因为DiapatcherServlet在初始化的时候会去
/WEB-INF/下加载该配置文件。

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多