Announcement Announcement Module
No announcement yet.
Spring Bean inside a Non-Spring-Object Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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.
    <object class="com.example.util.ColorManager" id="colorManager"/>
    <object class="">
      <property name="colorManager" ref="colorManager"/>
    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.
    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!


  • #2
    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

      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.




      • #4
        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.



        • #5

          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.


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