Results 1 to 5 of 5

Thread: Spring Bean inside a Non-Spring-Object

  1. #1
    Join Date
    May 2010
    Posts
    9

    Default Spring Bean inside a Non-Spring-Object

    Hello Forum,

    since I'm kind of new to Spring itself I'm trying to use a Spring managed Object inside a class that is not managed by Spring.

    I don't even know if this is possible, so excuse me if this question is totally out of logic. I'm just trying to learn Spring

    Suppose I have the following applicationContext.xml that loads fine and all that.
    Code:
    <objects>
    ...
    <object class="com.example.util.ColorManager" id="colorManager"/>
    ...
    
    <object class="com.example.foo.SimpleObject">
      <property name="colorManager" ref="colorManager"/>
    </object>
    </objects>
    And suppose I have a class Category that gets instantiated somewhere deep in the hierarchy of SimpleObject. Let's say that Category is a class representing a model or so.
    What I wann do now is that I want to call the colorManager inside of my Category Class. And I would like to use the one defined and instantiated in the container.
    Code:
    class Category {
    ...
     private var _colorManager:ColorManager;
    ...
    
    public function someFunctionName():Color {
      return  this._colorManager.getColorForCategory();
    }
    }
    I also implemented the setter for the colorManager property. So I would have guessed that all classes are scanned and that objects that are not defined in the context get the appropriate beans assigned.

    Or is this wrong?

    Thanks for your help!

    norman

  2. #2
    Join Date
    May 2010
    Posts
    9

    Default

    So nobody has any idea about this? Maybe I didn't explain myself correctly: I want to inject spring managed objects into non spring managed objects. I guess it's like the autowiring thing but I also want to wire non stage objects.

    Is there any way to do this?

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

    Default sorry

    Hi Norman,

    the short answer is: no.

    You can only inject objects that have been created by the container, stage objects being the exception to that. But if you just create an instance somewhere in your code there is no way for the container to detect this and auto-magically inject it.

    cheers,

    Roland

  4. #4
    Join Date
    May 2010
    Posts
    9

    Default

    Hi Roland,

    just to be clear: I wanna inject objects from the container into objects that are not managed.

    For example I wann inject the preferenceService, which is managed by the container into a simple Object, which is not managed by the container.

    [Autowired or Inject or whatever]
    var preferenceService:PreferenceService

    I can do that in the Spring Java world and I hoped that this would be possible in spring actionscript. But I guess this is not possible.

    cheers,
    norman

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

    Default nope

    Hey Norman,

    nope, I'm sorry, its technically impossible in actionscript/flash to get that to work.
    The only way to get this SORT OF working is through the createInstance() method:

    Instantiating a Class with [Autowire] annotations

    But in that case you still need a reference to the container to instantiate your class.

    cheers,

    Roland
    Last edited by 666shooter; Jun 12th, 2010 at 03:32 AM. Reason: Added alternative solution for problem

Posting Permissions

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