@Component
@Scope(value = "prototype")
public class Programmer {
@Autowired
@Qualifier("laptop")
private Computer machine;
private final int salary;
public Programmer(int salary) {
this.salary = salary;
}
public int getSalary() {
return salary;
}
void code() {
System.out.println("Programmer is coding with " + machine.getClass().getName());
}
}
I want to get a bean of this component and set different salary for different objects of this class.
I tried looking for something relevant but couldn’t find anything.
I got solution like doing:
@Configuration
@ComponentScan("com.classbasedconfig")
public class config {
@Bean
@Scope(value="prototype")
public Programmer programmer() {
return new Programmer(1000);
}
}
or using @Value annotation. But I want to get a bean with different values for salary. How do I do this? I do not want to use XML based config. Is this possible?