开发者

Recommended way to access Spring Context in a JMS Listener

I am working in a Web Application running in JBoss that utilizes Spring and whenever requests come into the application our web layer gets access to the Spring ApplicationContext via

ApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(request.getSession().getServletContext() );

We are ad开发者_StackOverflow中文版ding some JMS Listeners in our application that also need access to ApplicationContext, but unfortunately the JMS Listeners don't have access to the HttpServletRequest api.

What is the best practice in Spring to get access to the ApplicationContext inside a MessageListener. Our JMS Listeners are also injected via our spring configuration files.


If your JMS listeners are themselves Spring beans, as you suggest, then why not just wire the resources needed by the listener directly into it? The listener is just like any other bean - don't fetch the beans from the context, have them injected.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜