0

I'm trying to understand the following code

@Bean
@ConditionalOnMissingBean(name = "monitor")
@ConditionalOnBean(name={"identity"})
@Autowired
public MyObject myObject(@Qualifier("identity") Identity identity) {
    return new MyObject(clientFactory);
}

What purpose does @Autowired serve?

To my mind it seems redundant. At a guess the writer might believe it required to support the Identity injection. But, AFAIK, @Bean will do that.

----Edit----

Might need to mention that the example I've seen before is inside a @Configuration class.

@Bean
public AnotherObject anotherObject(Environment env) {
    return new AnotherObject(env);
}
Shane Gannon
  • 6,770
  • 7
  • 41
  • 64
  • Possible answer here? https://stackoverflow.com/questions/34172888/difference-between-bean-and-autowired#34174782 – jrsall92 Sep 12 '18 at 15:32
  • Possible duplicate https://stackoverflow.com/questions/32078600/why-do-i-not-need-autowired-on-bean-methods-in-a-spring-configuration-class – Savior Sep 12 '18 at 15:37
  • Can confirm - it's a duplicate. I was caught out by @Configuration. – Shane Gannon Sep 12 '18 at 16:19

0 Answers0