简体   繁体   English

Spring bean基于属性

[英]Spring beans based on properties

I am wondering if the below is possible in Spring 我想知道以下是否可能在春天

  1. Read a property file using spring - this file has a list of jms queue names 使用spring读取属性文件 - 此文件包含jms队列名称列表
  2. Make spring loop on the above list and define beans that define Apache camel routes from that queue to a file 在上面的列表中创建spring循环,并定义将该队列中的Apache camel路由定义到文件的bean

I could just create the routes using java code on the apache camel context, but wondering if it is possible through spring. 我可以在apache camel上下文中使用java代码创建路由,但想知道是否可以通过spring。

Reading a property file in a Spring XML wiring file is easy; 在Spring XML布线文件中读取属性文件很容易; eg using a PropertiesFactoryBean . 例如,使用PropertiesFactoryBean However, the second part of the problem cannot (I believe) be solved without writing a significant amount of Java code. 但是,问题的第二部分不能(我相信)在不编写大量Java代码的情况下得到解决。

I suggest that you read Section 3.8.3 of the Spring Reference that describes how to write your own FactoryBean classes. 我建议你阅读Spring Reference的3.8.3节 ,它描述了如何编写自己的FactoryBean类。 Another possibility is to create a custom Java configuration bean as described in Section 3.11 . 另一种可能性是创建一个自定义Java配置bean,如3.11节所述。 There may be other possibilities too. 可能还有其他可能性。

Warning: none of this stuff is particularly straight-forward if you are coming at it for the first time. 警告:如果你是第一次来这里,这些东西都不是特别直截了当。

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

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