dependency injection - inject beans into an abstract class with spring and java ee 5 -


i injecting spring-managed bean abstract class , seems doesn't work. here explanation of do, if not enough, can edit post , add code:

  1. implement java code - 1 abstract class, 2 classes inherit , bean injected , used in abstract class , subclasses.
  2. define bean in spring config.
  3. define abstract class , 2 subclasses in spring config.
  4. define first bean property of abstract class bean.

result - it's not working.

then tried move injected bean abstract class 2 subclasses. works.

so, did wrong, or theoretically impossible inject bean abstract class spring 3 , java ee 5?

is theoretically impossible inject bean abstract class spring 3 , java ee 5?

dependency injection happens on object not class. spring injects dependencies managed beans objects instantiated spring. since, abstract class cannot instantiated conceptually wrong think di here.

on related note, can define non-abstract class abstract spring bean adding attribute abstract=true <bean> tag. indicates bean not instantiated , serve mere template of properties other beans can use through bean inheritance (which isn't related java inheritance @ all).

in context well, (if you've configured it) dependency injection happen child beans , not parent bean since has been defined abstract. (note: it's not mandatory parent bean abstract makes sense when act set of common bean properties.)


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -