I am using Spring Boot annotation configuration. I have a class whose constructor accepts 2 parameters (string, another class).
Fruit.java
public class Fruit {
public Fruit(String FruitType, Apple apple) {
this.FruitType = FruitType;
this.apple = apple;
}
}
Apple.java
public class Apple {
}
I have a class that needs to autowire the above class by injecting parameters to the constructor("iron Fruit",Apple class)
Cook.java
public class Cook {
@Autowired
Fruit applefruit;
}
The cook class need to autowire Fruit class with parameters("iron Fruit",Apple class)
The XML configuration looks like this:
<bean id="redapple" class="Apple" />
<bean id="greenapple" class="Apple" />
<bean name="appleCook" class="Cook">
<constructor-arg index="0" value="iron Fruit"/>
<constructor-arg index="1" ref="redapple"/>
</bean>
<bean name="appleCook2" class="Cook">
<constructor-arg index="0" value="iron Fruit"/>
<constructor-arg index="1" ref="greenapple"/>
</bean>
How to achieve it using annotation configuration only?