spring配置文件拆分策略及方法
一、拆分策略
- 如果一个开发人员负责一个模块,我们采用公用配置(包括数据源、事务等)+每个系统模块一个单独配置文件(包括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配置文件拆分策略及方法的更多相关文章
- Spring配置文件解析--集合注入方法
<bean id="moreComplexObject" class="example.ComplexObject"> <property n ...
- Spring基础15——通过工厂方法来配置bean
1.什么是工厂方法 这里的工厂方法指的是创建指定bean的方法.工厂方法又分为静态工厂方法和实例工厂方法. 2.静态工厂方法配置bean 调用静态工厂方法创建Bean是将对象创建的过程封装到静态方法中 ...
- 读取spring配置文件的方法(spring读取资源文件)
1.spring配置文件 <bean id="configproperties" class="org.springframework.beans.factory. ...
- Spring配置文件外部化配置及.properties的通用方法
摘要:本文深入探讨了配置化文件(即.properties)的普遍应用方式.包括了Spring.一般的.远程的三种使用方案. 关键词:.properties, Spring, Disconf, Java ...
- Java中spring读取配置文件的几种方法
Spring读取配置XML文件分三步: 一.新建一个Java Bean: package springdemo; public class HelloBean { private String hel ...
- 使用import简化spring的配置 spring import 标签的解析 使用import或加载spring配置时,报错误There is no ID/IDREF 多个Spring配置文件import resource路径配置
spring-import 标签的解析.使用案例: 对于spring配置文件的编写,我想,对于经历过庞大项目的人,都有那种恐惧的心理,太多的配置文件.不过,分模块都是大多数人能想到的方法,但是,怎么分 ...
- SpringMVC 学习 九 SSM环境搭建 (二) Spring配置文件的编写
spring配置文件中需要干的事情 (一)开启 Service与pojo包的注解扫描 注意:spring 扫描与表对应的实体类,以及service层的类,不能用来扫描Controller层的类,因为 ...
- 使用Spring Security3的四种方法概述
使用Spring Security3的四种方法概述 那么在Spring Security3的使用中,有4种方法: 一种是全部利用配置文件,将用户.权限.资源(url)硬编码在xml文件中,已经实现过, ...
- Spring Data JPA 梳理 - 使用方法
1.下载需要的包. 需要先 下载Spring Data JPA 的发布包(需要同时下载 Spring Data Commons 和 Spring Data JPA 两个发布包,Commons 是 Sp ...
随机推荐
- 日照学习提高班day3测试
A 思路: 一看到'#''.'什么的就想到搜索怪我怪我... 这道题勉强说是搜索别打我qwq 1)因为不重复,所以首先要判断是否%5==0,若不满足,直接输出NO 2)弄个vis数组记录是否被搜过,如 ...
- Loooooooooooooooong time no see!
好久没来啦~去年这会一口气写了好多,是因为即将离职,在公司闲的没事,再加上也积累了一些东西想分享. 最近有个朋友给我私信求助,才又想起这里.这快一年时间,又学习了不少东西.从何写起呢,哈哈,不知道啊~ ...
- centos 7 php7 yum源
rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm rpm -Uvh https://mir ...
- A. Sea Battle
A. Sea Battle time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- LNMP源码编译
LNMP源码编译 编译安装之前把开发包组安装了 [root@tiandong63 ~]# yum groupinstall "Development Tools" "De ...
- devServer之proxy跨域
配置 注意:修改之后要重新运行一遍项目才行 devServer:{ contentBase:'./', proxy:{ // 当你请求是以/api开头的时候,则我帮你代理访问到http://local ...
- LightGBM GPU python版本安装
失败的安装尝试 1.官方Guide https://lightgbm.readthedocs.io/en/latest/GPU-Windows.html 生成在windows下可执行的exe程序,但是 ...
- Python3并发写文件
使用python2在进行并发写的时候,发现文件会乱掉,就是某一行中间会插入其他行的内容. 但是在使用python3进行并发写的时候,无论是多进程,还是多线程,都没有出现这个问题,难道是python3的 ...
- python--nolocal
Compare this, without using nonlocal: x = 0def outer(): x = 1 def inner(): x = 2 print("inner:& ...
- 使用data_flow_ops构造batch数据集
1. tf.unstack(number, axis=0) 表示对数据进行拆分 import tensorflow as tf import numpy as np data = np.array( ...