java - Inject inherited property values using CDI-Weld -
i'm developing basic swing application and, if tend use spring ioc (with xml configuration) dependency injection want give try cdi-weld. having following structure done in spring, container creates schoolboy
, universitystudent
, each 1 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 similar in cdi using @inject @config
annotations. however, every single time see this, they're above property and, being inherited property, cannot classes here. how achieve each student
subclass own name
value?
update
injecting values in subclasses doesn't mean hardcoding them in configuration file. property value can acquired .properties file. given edge case student
legacy project , want innherit classes , inject property, solution be?
cdi doesn't support xml configuration natively. have use library solder achieve this. it's bad practice , discouraged set bean properties configure dependency management (spring.xml) not type , refactor safe. other option use producer method set needed value:
public schoolboy produceschoolboy { //construct new schoolboy() , set name }
and have producer different student types. not flexible work.
Comments
Post a Comment