一、拆分策略

  • 如果一个开发人员负责一个模块,我们采用公用配置(包括数据源、事务等)+每个系统模块一个单独配置文件(包括Dao、Service、Web控制器)的形式
  • 如果是按照分层进行的分工,我们采用公用配置(包括数据源、事务等)+DAO Bean配置+业务逻辑Bean配置+Web控制器配置的形式

二、拆分方法

如果有多个配置文件需要载入,可以分别传入多个配置文件名,或以String[]方式传入多个配置文件名。或者还可以采用通配符(*)来加载多个具有一定命名规则的配置文件。如下

ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml", "applicationContext-dao.xml", "applicationContext-jdbc.xml");
String[] configs = {"applicationContext.xml", "applicationContext-dao.xml", "applicationContext-service.xml"};
ApplicationContext ctx = new ClassPathXmlApplicationContext(configs);
ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext*.xml");

建议通过通配符(*)的方式配置多个Spring配置文件,建议在给Spring配置文件命名时遵循一定的规律

此外,Spring配置文件本身也可以通过<beans>标签下的import子元素导入其他配置文件,将多个配置文件整合到一起,形成一个完整的Spring配置文件

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"> <import resource="classpath:applicationContext-dao.xml"/>
<import resource="classpath:applicationContext-service.xml"/> </beans>

spring配置文件拆分策略及方法的更多相关文章

  1. Spring配置文件解析--集合注入方法

    <bean id="moreComplexObject" class="example.ComplexObject"> <property n ...

  2. Spring基础15——通过工厂方法来配置bean

    1.什么是工厂方法 这里的工厂方法指的是创建指定bean的方法.工厂方法又分为静态工厂方法和实例工厂方法. 2.静态工厂方法配置bean 调用静态工厂方法创建Bean是将对象创建的过程封装到静态方法中 ...

  3. 读取spring配置文件的方法(spring读取资源文件)

    1.spring配置文件 <bean id="configproperties" class="org.springframework.beans.factory. ...

  4. Spring配置文件外部化配置及.properties的通用方法

    摘要:本文深入探讨了配置化文件(即.properties)的普遍应用方式.包括了Spring.一般的.远程的三种使用方案. 关键词:.properties, Spring, Disconf, Java ...

  5. Java中spring读取配置文件的几种方法

    Spring读取配置XML文件分三步: 一.新建一个Java Bean: package springdemo; public class HelloBean { private String hel ...

  6. 使用import简化spring的配置 spring import 标签的解析 使用import或加载spring配置时,报错误There is no ID/IDREF 多个Spring配置文件import resource路径配置

    spring-import 标签的解析.使用案例: 对于spring配置文件的编写,我想,对于经历过庞大项目的人,都有那种恐惧的心理,太多的配置文件.不过,分模块都是大多数人能想到的方法,但是,怎么分 ...

  7. SpringMVC 学习 九 SSM环境搭建 (二) Spring配置文件的编写

    spring配置文件中需要干的事情 (一)开启  Service与pojo包的注解扫描 注意:spring 扫描与表对应的实体类,以及service层的类,不能用来扫描Controller层的类,因为 ...

  8. 使用Spring Security3的四种方法概述

    使用Spring Security3的四种方法概述 那么在Spring Security3的使用中,有4种方法: 一种是全部利用配置文件,将用户.权限.资源(url)硬编码在xml文件中,已经实现过, ...

  9. Spring Data JPA 梳理 - 使用方法

    1.下载需要的包. 需要先 下载Spring Data JPA 的发布包(需要同时下载 Spring Data Commons 和 Spring Data JPA 两个发布包,Commons 是 Sp ...

随机推荐

  1. BZOJ 2651 城市改建 树形DP+模拟?

    题意 给一颗树,删除一条边再加一条边,使它仍为一颗树且任意两点间的距离的最大值最小. 题目数据范围描述有问题,n为1或重建不能使任意两点距离最大值变小,可以输出任意答案. 分析 删除一条边后会使它变成 ...

  2. 编译报错:File ended while scanning use of xxx

    出现这个问题的原因是使用某些命令时,给出的参数不完整或者漏了半个大括号: 比如, Runaway argument? {adaptivity, dynamically changing environ ...

  3. [题解] [TJOI2011] 构造矩阵

    题面 题解 很容易看出来是道网络流的题目, 要是没有这个字典序最小, 直接建图跑一遍就好了, 考虑如何输出字典序最小的方案 我们可以贪心地去选择, 若当前点可以选0就选0, 不能选0就选1, 有一点像 ...

  4. Linux常用指令grep(搜索过滤)

    Linux系统中grep命令是一种强大的文本搜索工具,它能使用正则表达式搜索文本,并把匹 配的行打印出来.grep全称是Global Regular Expression Print,表示全局正则表达 ...

  5. ajax+php (jquery.form插件)实现异步文件上传

    <!DOCTYPE html> <html lang="CN"> <head> <title>upload model</ti ...

  6. 认识git的简单命令

    一.课程目的 教大家学会it的简单命令(老师建议 English 的前后要加空格) 二.认识 git 命令 整篇文章都是用语雀写的. 解释了(使用git)绑定gitee的操作 https://www. ...

  7. NullPointerException 没有堆栈

    周五在公司搭好的ELK上查看日志,组长让看看其中NullPointerException出现很多的原因. 通过NullPointerException搜索,点看其中一个查看,发现异常的信息就一行jav ...

  8. LC 425. Word Squares 【lock,hard】

    Given a set of words (without duplicates), find all word squares you can build from them. A sequence ...

  9. html+xml+servlet 通讯录案例demo

    首先导入dom4j和xPath技术以及测试对应的jar包 package com.loaderman.demo.entity; /** * 实体对象 * @author APPle * */ publ ...

  10. View的事件机制

    为了更好的研究View的事件转发,我们自定以一个MyButton继承Button,然后把跟事件传播有关的方法进行复写,然后添加上日志. import android.content.Context; ...