Announcement Announcement Module
Collapse
No announcement yet.
Inject dependent object via its one argument constructor using @Inject of JSR 330 Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Inject dependent object via its one argument constructor using @Inject of JSR 330

    Hi,
    I want to use @Inject of JSR 330,my requirment is given below as an example.

    public class A{

    //Step 1
    @Inject
    B b;

    }

    public class B extends C{

    //B's one argument constructo
    public B(String configFileName){
    super(configFileName)
    }

    public class C{

    //C's one argument constructo
    public C(String configFileName){
    //some businees logic here
    .........
    }


    Now my problem is that how can i inject B's object(means using @Inject as in step 1) so that public B(String configFileName) is invoked.What i need to change in step 1.

    Thanks in Advance.

  • #2
    Put the @Inject on the constructor instead of the field.

    Comment


    • #3
      Thanks Marten for your reply.But can you plz clarify on which constructor can you plz write down syntax of that constructor.

      Comment


      • #4
        You need to change the constructor of class B (not of class A). Class a only wants to know that it needs to get a reference to an instance of class B you cannot drive how that is constructed from class A. So you will need to modify the constructor for class B...

        Comment

        Working...
        X