Hi,
I've tried set the property in the following way:
@Component
public class Empl {
private int age;
public Empl() {}
public Empl( @Value("4") int age ) {
this.age = age;
}
}
It doesn' work. Where am I wrong?
Hi,
I've tried set the property in the following way:
@Component
public class Empl {
private int age;
public Empl() {}
public Empl( @Value("4") int age ) {
this.age = age;
}
}
It doesn' work. Where am I wrong?
Does anybody know?
Ok,
I know now. You should use @Autowired to indicate a constructor to create bean
Because you had a default constructor on the Empl class. That is the one that would get called by default by the Spring container.
Which is why you had to add @Autowired for the non default constructor.
The thing that I'm not sure about is if you did not have a default constructor would Spring container have called the non-default one?
My guess is probably not, and it would have thrown an exception- no default constructor found.
-Amit