手动拉弹簧豆的最佳方法? [英] Best way to manually pull a spring bean?

查看:42
本文介绍了手动拉弹簧豆的最佳方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何手动拉动春豆​​?我有一个相当大的Web应用程序,并且在给定的服务中,一个临时对象需要访问特定于机器的Bean(数据库连接信息).由于该应用程序在集群中运行,因此该临时对象(可以在服务器之间反弹)始终需要从当前spring上下文和服务器中获取正确的连接.

How do I pull a spring bean manually? I have a rather large web application, and in a given service, a transient object requires access to a bean that is machine specific (database connection info.) Since the application runs in a cluster, this transient object (which can bounce between servers) always needs to grab the correct connection been from the current spring context and server.

那么,手动将豆从弹簧中拔出的最佳方法是什么?

So, what's the best way to manually pull a bean out of spring?

推荐答案

您可以让您的服务实现

You could have your service implement ApplicationContextAware so that you have access to the ApplicationContext itself and can call getBean() directly on it.

这篇关于手动拉弹簧豆的最佳方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆