简体   繁体   English

Spring ApplicationContext Bean接线

[英]Spring ApplicationContext Beans-wiring

I have two ApplicationContexts for my project (very huge project). 我的项目有两个ApplicationContext(非常大的项目)。 One old xml with data 一个带有数据的旧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>

now I need to add my other project applicatinContext to it or any other way so that none of the modules will be impacted 现在,我需要向其添加其他项目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>

the first one has Auto-wiring enabled and this one has and needs manual wiring. 第一个启用了自动接线,而第一个需要手动接线。 How can i combined both of them to put into one xml or read two configurations. 我如何才能将它们两者组合成一个xml或读取两个配置。

I don't see why reading two or more application context files is difficult. 我不明白为什么很难读取两个或多个应用程序上下文文件。 The usual Spring idiom is to partition configuration according to layer. Spring惯用的习惯用法是按层划分配置。 I typically have configuration for persistence, service, web, etc. If it's a web application, I just add all of them in using the ContextLoaderListener . 我通常对持久性,服务,Web等进行配置。如果是Web应用程序,则只需使用ContextLoaderListener来添加所有它们。 You can specify as many configuration files as you need. 您可以根据需要指定任意数量的配置文件。

I would consider one huge configuration file a liability in the same way that I would look down on one huge class for everything. 我会认为一个巨大的配置文件是一种责任,就像我看不起一个大型类的所有东西一样。 Decomposition is a computer science fundamental. 分解是计算机科学的基础。 I'd recommend partitioning your configuration. 我建议对您的配置进行分区。

Mixing annotation-based and XML-based configuration isn't a problem, either. 混合基于注释和基于XML的配置也不是问题。

You'll only have an issue if the two configurations overlap. 如果两个配置重叠,您只会遇到问题。 You'll have to remove one or the other for the conflicted beans. 您必须删除有冲突的bean中的一个。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM