I'm developing a basic Swing application and, even if I always tend to use Spring Ioc (with xml configuration) for dependency injection I want to give a try to CDI-Weld. Having the following structure done in Spring, the container creates a SchoolBoy
and a UniversityStudent
, each one with its name.
public class Student{
protected String name;
public void setName(String name){
this.name = name;
}
}
public class SchoolBoy extends Student{
}
public class UniversityStudent extends Student{
}
<bean class="SchoolBoy">
<property name="name" value="Daniel" />
</bean>
<bean class="UniversityStudent">
<property name="name" value="Rose" />
</bean>
I've seen it's possible to do something similar in CDI using @Inject @Config
annotations. However, every single time I see this, they're above the property itself and, being an inherited property, I cannot do that for my classes here. How do I achieve each Student
subclass to get its own name
value?
UPDATE
Injecting that values in subclasses doesn't necessarily mean hardcoding them in the configuration file. The property value itself can be acquired from a .properties file. However given the edge case that Student
is into a legacy project and I want to innherit my classes from it and inject that property, what could the solution be?