spring配置文件的分解

本文介绍了一种将Spring配置文件按模块分解的方法,通过这种方式提高了代码的可读性和可维护性,并减少了团队开发中因多人修改同一文件而产生的冲突。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

把spring配置分解按模块分解,比把成百个bean写到一个文件中要清楚的多,找bean修改也方便的多,同时减少团队开发修改一个文件产生的冲突。

 

web中的配置

<context-param>
		<param-name>contextConfigLocation</param-name>
		<param-value>WEB-INF/classes/spring*.xml</param-value>
</context-param>

<listener>
		<listener-class>
			org.springframework.web.context.ContextLoaderListener
		</listener-class>
	</listener>
	<listener>
		<listener-class>
			org.springframework.web.context.request.RequestContextListener
		</listener-class>
	</listener>

 

 

spring主文件spring.xml

<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.0.xsd">
    
    <bean id="springUtil" class="com.cplat.util.SpringUtil"></bean>

	<import resource="classpath:com/cplat/**/spring-*.xml" />
	
</beans>

 

模块中的配置文件

<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.0.xsd">

   <bean id="userDao" class="com.cplat.modules.user.UserDaoImpl">
        <property name="sessionFactory" ref="sessionFactory"></property>
   </bean>
   <bean id="userService" class="com.cplat.modules.user.UserServiceImpl">
        <property name="userDao" ref="userDao"></property>
   </bean>
   <bean id="userAction" class="com.cplat.modules.user.UserAction">
        <property name="userService" ref="userService"></property>
        <property name="roleService" ref="roleService"></property>
   </bean>
</beans>

 项目结构图


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值