You could do it with a
@Qualifier
annotation. Of course that means that you have added Logger
objects to your application context already.
Importing this config into your application context would allow you to do that:
@Configuration
public class LoggerConfig {
@Bean
public Logger myClassLogger() {
return LoggerFactory.getLogger(MyClass.class);
}
@Bean
public Logger myOtherClassLogger() {
return LoggerFactory.getLogger(MyOtherClass.class);
}
}
And then in your classes that uses the
Logger
:@Component
public class MyClass {
@Autowired
@Qualifier("myClassLogger")
private Logger logger;
//...
}
@Component
public class MyOtherClass {
@Autowired
@Qualifier("myOtherClassLogger")
private Logger logger;
//...
}
No comments:
Post a Comment