Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: Problems while autowiring to from child to parent context

  1. #1
    Join Date
    Aug 2010
    Location
    Aix en Provence
    Posts
    7

    Default Problems while autowiring to from child to parent context

    Hello everyone,

    we are creating a composite application framework on the top of Spring AS "building blocks" (we do not use Flex modules but our own modular architecture).

    The top-level application defines an app context and loads "modules" defined locally (into the same SWF artifact) or remotely, each of them defining a child context. The issue we are facing is that we have not been able to autowire properties of objects created from the children contexts to object instances provided by the top-level one (seems that candidates are only searched into the objectDefinitions from the children). This forces to wire collaborators from parent context using refs.

    I could be wrong, but I think that the Java implementation of Spring allows autowiring from child to parent. Is it a bug, are we doing something wrong or is there particular reasons to forbid such practices ? If so, could anyone suggest some sort of approach to avoid using refs ?

    Many thanks,
    Jef

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,624

    Default

    Spring doesn't allow that... The child can access the parent, the parent knows nothing about the childeren.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  3. #3
    Join Date
    Aug 2010
    Location
    Aix en Provence
    Posts
    7

    Default

    Hi Martin,

    thanks for answering.

    Accessing the parent from the child is exactly what I'm trying to do. To clarify, if I declare an object in the parent context :

    Code:
    <object id="a" class="tld.org.projet.A"/>
    and refer to the object A in the child context :

    Code:
    <object id="b" class="tld.org.projet.B">
        <property name="refToA" ref="a"/>
    </object>
    ... everything works fine. Using the same declaration in the parent context and trying to autowire the refToA property :

    Code:
    public class B
    {
        [Autowired]
        public var refToA : A;
    }
    ... Spring complains it does not find any candidate for AW. As B has been created by the object factory corresponding to the child context the autowiring attempt is performed at the child level.

  4. #4
    Join Date
    Dec 2008
    Location
    Brussels
    Posts
    406

    Default might be a bug, not sure

    Hey Jeff,

    it seems like a bug from your description, can you post a small example project that demonstrates the problem? That we'll be able to more easily determine where things go wrong.

    thanks in advance,

    Roland

  5. #5
    Join Date
    Aug 2010
    Location
    Aix en Provence
    Posts
    7

    Default

    Hey Roland,

    sorry for late answer. Here you may find three variants of the same project :
    - in the first case, the collaborator is injected using autowiring, there is a single context : works properly ;
    - in the second case, the collaborator is injected autowiring, but this time there are a child and a parent context : fails to find a candidate for autowiring ;
    - in the third case, there are two contexts but the collaborator is not autowired but injected using a reference : works properly.

    Hope this helps,
    Jef.

  6. #6
    Join Date
    Dec 2008
    Location
    Brussels
    Posts
    406

    Default thx

    Hey Jef,

    I'll try and have a look at your examples asap, right now I'm a bit swamped at the office but I promise I'll have a look later this week. I suspect that the issue lies with autowiring by type which doesn't take a potential parent context in account, but I'm not sure, I'll have to investigate.
    Thank you for taking the time to post the examples!

    cheers,

    Roland

  7. #7
    Join Date
    Aug 2010
    Location
    Aix en Provence
    Posts
    7

    Default

    Hey Roland,

    the intuition about this issue is right. I created a patch for the DefaultAutowireProcessor class.

    I add to use the ugly
    Code:
    ( factory is IApplicationContext )
    expression in line 428 because the IObjectFactory interface does not expose the "parent" property (it seems that it was the case but for some reason the code has been commented out at some time, see there).

    Thanks for your answer,
    Jef.
    Attached Files Attached Files

  8. #8
    Join Date
    Dec 2008
    Location
    Brussels
    Posts
    406

    Default ...

    Hey Jef,

    yea, I had noticed the commenting out of the parent property in that particular interface earlier, in the trunk version its back, so in version 1.0 it'll be back I'll review your patch asap, cheers!

    Roland

  9. #9
    Join Date
    Aug 2010
    Location
    Aix en Provence
    Posts
    7

    Default

    Roland,

    I guess i'll eagerly wait for the 1.0 release.

    Cheers !
    Jef

  10. #10
    Join Date
    Dec 2008
    Location
    Brussels
    Posts
    406

    Default

    I've implemented the autowiring by type which takes a parent factory into account as well, I've did it in a slightly different way then your patch though.

    Version 1.0 will be released either today or somewhere this weekend, I'm sifting through the last tidbits at the moment. But it'll be ready real soon now

    cheers,

    Roland

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •