SLF4J记录仪的弹簧构造器注入 - 如何获得注入目标类?
2022-09-02 19:46:33
我正在尝试使用Spring将SLF4J记录器注入到这样的类中:
@Component
public class Example {
private final Logger logger;
@Autowired
public Example(final Logger logger) {
this.logger = logger;
}
}
我找到了我实现的类。但问题是我无法获得有关注射目标的任何信息:FactoryBean
public class LoggingFactoryBean implements FactoryBean<Logger> {
@Override
public Class<?> getObjectType() {
return Logger.class;
}
@Override
public boolean isSingleton() {
return false;
}
@Override
public Logger getObject() throws Exception {
return LoggerFactory.getLogger(/* how do I get a hold of the target class (Example.class) here? */);
}
}
FactoryBean是正确的选择吗?当使用微量容器工厂注射时,您可以获得传递的目标。在guice中,它有点棘手。但是,如何在春季实现这一目标呢?Type