考虑到以下类别:
class A
{
@Inject
private B b;
}
class B
{
}
@Configuration
class SomeConfiguration
{
@Bean
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public B b()
{
// Is there a way to get the information of the class that requests for this bean within this body of the bean definition method?
// Ie. the class name of the requesting class
}
}
可以在bean定义方法的主体中访问请求类的信息吗?
1条答案
按热度按时间ubbxdtey1#
如果
B
是个记录者,需要知道A
,则应该使用工厂模式,类似于所有日志框架的工作方式。日志框架通常只有一个全局工厂。有了Spring,你应该在工厂里注射。
例子: