为什么POM中的依赖顺序会影响bean可见性

时间:2015-07-09 08:23:27

标签: java spring maven

我正在尝试将一个组件连接到现有系统。为此,我将对组件(DataFilter)的依赖包含到主项目POM文件中。

订单1)

<dependency>
  <groupId>${project.groupId}</groupId>
  <artifactId>DataFilter</artifactId>
  <version>1.0.0-SNAPSHOT</version>
</dependency>
<dependency>
  <groupId>${project.groupId}</groupId>
  <artifactId>CommandHandler</artifactId>
  <version>1.0.0-SNAPSHOT</version>
</dependency>

这样的顺序(只有POM文件中的依赖项;没有导入调用)会导致该系统在启动时预先实例化以下bean:

  • 来自主应用(blueprint.xml

    [activemq,parser,rawStorage,commandDAO,CommandService,payloadStorage,payloadRetrieval,rawReply,rawRetrieval,template,consumerTemplate,app-context:beanPostProcessor,app-context]; 

  • 来自组件DataFilter

  • [filters,hdop_filter_pass_less_than_4,vdop_filter_pass_less_than_4,speed_filter_pass_less_than_high_speed,event_and_gps_time_diff_less_than_exp_time,fix_type_recomended_to_3dfix,always_pass_when_motion_or_stationary] 

  • 并且看不到bean iCommandService导致无法在主应用中创建rawReply的原因

     Exception encountered during context initialization - cancelling refresh attempt
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'rawReply' defined in class path resource [OSGI-INF/blueprint/packaging-jar-camel-context-xml.txt]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [com.company.product.CommandHandler.InitialClass]: Constructor threw exception; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'iCommandService' is defined 

当我将依赖关系切换到订单2)(先CommandHandler

<dependency>
  <groupId>${project.groupId}</groupId>
  <artifactId>CommandHandler</artifactId>
  <version>1.0.0-SNAPSHOT</version>
</dependency>    
<dependency>
  <groupId>${project.groupId}</groupId>
  <artifactId>DataFilter</artifactId>
  <version>1.0.0-SNAPSHOT</version>
</dependency>

出现以下行为:

  • 主应用仍然按上述方式预先实例化

    [activemq,parser,rawStorage,commandDAO,CommandService,payloadStorage,payloadRetrieval,rawReply,rawRetrieval,template,consumerTemplate,app-context:beanPostProcessor,app-context] 

  • 组件命令处理程序(这些bean在顺序1中不可见))预先实例化其bean

    [iCommandServicecommandDAO]

  • 在设置驼峰上下文时,甚至没有提到
  • 组件数据过滤器;没有预先实例化数据过滤器bean,没有关于丢失bean的错误。

  • 驼峰上下文启动并正确构建路径

此外

  • 命令处理程序和数据过滤器将其上下文保留在Beans.xml
  • 主要应用blueprint.xml(或packaging-jar-camel-context-xml.txt构建为jar,而不是捆绑)
  • Data Filer可编译为OSGi bundle
  • 没有使用自动装载

问题是:

  • 为什么家属要求影响能见度或不创造豆类
  • 当正确创建所有三个组件的所有bean时,如何正确设置它?

0 个答案:

没有答案