Injecting companies

Report a typo

Here is a set of beans representing different companies. Which one will be autowired in the person bean?

Java
@Bean
public Person person(@Qualifier("company1") Company company) {
    return new Person("John", company);
}

@Bean
public String address() {
    return "Park Avenue, 15";
}
    
@Bean(name = "company3")
public Company company1(String address) {
    return new Company("GoodInc", address);
}

@Bean
public Company company2(String address) {
    return new Company("Noodle", address);
}

@Bean(name = "company4")
public Company company3(String address) {
    return new Company("Hyperskill", address);
}

@Bean(name = "company1")
public Company company4(String address) {
    return new Company("AI Robots", address);
}
Kotlin
@Bean
fun person(@Qualifier("company1") company: Company): Person {
    return Person("John", company)
}

@Bean
fun address(): String {
    return "Park Avenue, 15"
}

@Bean(name = ["company3"])
fun company1(address: String): Company {
    return Company("GoodInc", address)
}

@Bean
fun company2(address: String): Company {
    return Company("Noodle", address)
}

@Bean(name = ["company4"])
fun company3(address: String): Company {
    return Company("Hyperskill", address)
}

@Bean(name = ["company1"])
fun company4(address: String): Company {
    return Company("AI Robots", address)
}
Select one option from the list
___

Create a free account to access the full topic