Spring根据逻辑分层配置
背景:
通常简单的项目 ,一个spring.xml的配置文件即可搞定,但是当项目足够大的时候,我们如果将web ,service ,dao这些层的配置都放在spring.xml中,那这个配置文件将相当庞大和混乱,不易维护。
解决:
一个比较好的做法是将配置文件分为三层写三个配置文件(spring-web.xml , spring-service.xml, spring-dao.xml)配置方法如下:
web.xml:
<?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:tx="http://www.springframework.org/schema/tx"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd"> <bean id="messageDAO" class="com.downjoy.app.messageboard.common.dao.ibatis.MessageDAOImpl"/> <bean id="userDAO" class="com.downjoy.app.messageboard.common.dao.ibatis.UserDAOImpl"/></beans>
当然还有一种方式就是在各个子配置文件中,将需要的父配置文件import进来,这里不具体展开。
欢迎转载,请注明出处 http://blog.csdn.net/wangyang2698341/article/details/7880493