Announcement Announcement Module
No announcement yet.
how to inject @Autowired when perform new Object() ? Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • how to inject @Autowired when perform new Object() ?

    I am Using spring mvc 3.1 and i have factory class with static method that perform "new Object()"

    and the Object contain @Autowired inside which return null.

    All the beans are in servlet-context.xml how can i perform new and sill use the @Autowired in

    the Objec ?


  • #2
    You can't. If you don't let the framework initialize the objects, then there is no injection (the @Autowired annotation is useless because there is no framework to process it). So new -> no injection. What you could do is replicate the behavior of your factory class inside the object's constructor, then register the object as a prototype bean.


    • #3
      Well actually you can... By using AspectJ and the @Configurable annotation.. All this is explained in the reference guide.