我正在尝试将一个组件连接到现有系统。为此,我将对组件(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
[iCommandService
,commandDAO
]
组件数据过滤器;没有预先实例化数据过滤器bean,没有关于丢失bean的错误。
驼峰上下文启动并正确构建路径
此外
Beans.xml
blueprint.xml
(或packaging-jar-camel-context-xml.txt
构建为jar,而不是捆绑)OSGi
bundle 问题是: