Spring ApplicationContext Beans-wiring

时间:2012-07-17 11:15:37

标签: java spring

我的项目有两个ApplicationContexts(非常庞大的项目)。 一个带有数据的旧xml

<?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或读取两个配置。

2 个答案:

答案 0 :(得分:3)

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

我会认为一个巨大的配置文件是一种负担,就像我会瞧不起一个庞大的类一样。分解是计算机科学的基础。我建议您对配置进行分区。

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

如果两个配置重叠,则只会出现问题。你必须为冲突的bean删除一个或另一个。

答案 1 :(得分:1)

相关问题