2012-07-17 84 views
0

我有两个ApplicationContexts用于我的项目(非常庞大的项目)。 一个旧的XML数据Spring ApplicationContext Bean-wiring

<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"> 
<beans default-autowire="autodetect"> 
</beans> 

现在我需要我的其他项目applicatinContext添加到它或任何其他方式,以使没有模块将受到影响

<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"> 

<beans xmlns="http://www.springframework.org/schema/beans" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" 
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"> 


<bean id="positionResponsesDAO" 
    class="com.xxx.modules.worklist.DAO.Impl.PositionResponsesDAOImpl"> 
    <property name="dataSource" ref="dataSource" /> 
</bean> 

<bean id="positionDAO" 
    class="com.xxx..modules.worklist.DAO.Impl.PositionDAOImpl"> 
    <property name="dataSource" ref="dataSource" /> 
</bean> 

<bean id="nextActionDAO" 
    class="com.xxx..modules.worklist.DAO.Impl.NextActionDAOImpl"> 
    <property name="dataSource" ref="dataSource" /> 
</bean> 
    <bean> 
     ....... few more 
    </bean> 

    <bean id="workOrderManager" class="com.xxx.modules.worklist.action.manager.impl.WorkOrderManagerImpl"> 
    <property name="positionDO" ref="positionDO" /> 
    <property name="moveWorkOrderDO" ref="moveWorkOrderDO" /> 
    <property name="nextActionDO" ref="nextActionDO" /> 
    <property name="positionDAO" ref="positionDAO" /> 
    <property name="moveResponsesDAO" ref="moveResponsesDAO" /> 
    <property name="moveWorkOrderDAO" ref="moveWorkOrderDAO" /> 
    <property name="nextActionDAO" ref="nextActionDAO" /> 
    <property name="positionResponsesDAO" ref="positionResponsesDAO" /> 
</bean> 


<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" 
    destroy-method="close"> 
    <property name="driverClass" value="oracle.jdbc.driver.OracleDriver" /> 
    <property name="jdbcUrl" value="driverUrl" /> 
    <property name="user" value="MCMGR" /> 
    <property name="password" value="MC123" /> 
</bean> 
    </beans> 

第一个具有自动 - 启用接线,并且此接线需要手动接线。我怎么可以将他们两个合并成一个XML或读取两个配置。

回答

3

我不明白为什么阅读两个或多个应用程序上下文文件很困难。通常的Spring成语是根据图层对配置进行分区。我通常配置持久性,服务,网络等。如果它是一个Web应用程序,我只需使用ContextLoaderListener将它们全部添加。您可以根据需要指定任意数量的配置文件。

我会考虑一个巨大的配置文件的责任,就像我会看着一个巨大的类一样。分解是计算机科学的基础。我建议分区你的配置。

混合注解和基于XML的配置也不是问题。

如果两种配置重叠,则只会有问题。您必须为冲突的bean移除一个或另一个。

+0

我试过没有成功:( – Reddy 2012-07-17 11:52:33

+0

我不知道“没有成功”的样子。 – duffymo 2012-07-17 12:57:03

相关问题