Is there any way to use
with @Component annotation (creating spring beans using annotation)?
I would like to create sprin
Following my comment, this piece of XML
is more or less eqivalent to this code (note that I created artificial Base
class since abstract beans in Spring don't need a class
):
public abstract class Base {
@Autowired
protected Foo foo;
}
@Component
public class Wallace extends Base {}
@Component
public class Gromit extends Base {}
Wallace
and Gromit
now have access to common Foo
property. Also you can override it, e.g. in @PostConstruct
.
BTW I really liked parent
feature in XML which allowed to keep beans DRY, but Java approach seems even cleaner.