Load multiple spring instances at runtime

不羁的心 提交于 2019-12-12 01:34:48

问题


I've built the spring application using Spring Integration (defined in xml) to listen on a specific JMS Topic, transform the data and publish it RabbitMQ queue. In the xml all the configuration data (for example topic name, url, username, password) I externalized to the properties file, which i load in xml using this entry:

It's working just fine, but now it appeared that I need to create a webservice that the client can connect to and specify the topic name that he's interested in. The server would then pass back the reference of the queue to which it publishes the transformed messages. I thought it would be nice to reuse the currently working application. It would require then to load the new independent spring context each time the client sends the request and specify the properties at runtime not in the config.properties file.

Now the questions: 1. It seems to be positive that each client's request is treated in complete isolation, however isn't an overkill to start multiple contexts(each time client wants a new topic to be listened)? 2. How to pass the properties other way than a config file? Can I for example somehow pass a Map of parameters instead of the file when starting the context?

Many thanks for your suggestions.


回答1:


The dynamic-ftp sample shows how to fire up a context with properties.

For an inbound adapter you might need to make the context a child context - that way you can share the downstream flow across the users by sending to a common channel.

There are links in the readme for how to do that; the answer to this question and its followup show a similar technique when using Java @Configuration with email adapters.



来源:https://stackoverflow.com/questions/36472229/load-multiple-spring-instances-at-runtime

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!