Announcement Announcement Module
Collapse
No announcement yet.
Can't get Autowired metadata to work Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Can't get Autowired metadata to work

    I'm trying to set up Spring Actionscript 0.8.1 on my Flex 4 project, but I'm having a hard time making it work with Autowired metadata annotations.

    I have the following applicationContext.xml file:
    Code:
    <objects>
    
    	<object id="channelSet" class="mx.messaging.ChannelSet">
    		<method-invocation name="addChannel">
    			<arg>
    				<object id="amfChannel" class="mx.messaging.channels.AMFChannel">
    					<property name="url" value="http://localhost:8080/conferenceguide/messagebroker/amf"/>
    				</object>
    			</arg>
    		</method-invocation>
    	</object>
    
    	<object id="adminService" class="org.epseelon.conferenceguide.service.AdminService">
    		<property name="channelSet" ref="channelSet" />
    		<property name="showBusyCursor" value="true" />
    	</object>
    
    </objects>
    And I load this context in my application with the following code:
    Code:
    [Autowired(mode="byName")]
    private var _adminService:AdminService;
    public function set adminService(service:AdminService):void{_adminService = service;}
    public function get adminService():AdminService{return _adminService;}
    
    private function applicationCompleteHandler():void
    {
    	_applicationContext = new FlexXMLApplicationContext(_contextURL);
    	_applicationContext.addEventListener(Event.COMPLETE, applicationContextLoaded);
    	_applicationContext.load();
    }
    
    private function applicationContextLoaded(event:Event):void
    {
    	adminService = _applicationContext.getObject("adminService");
    }
    If I leave the instruction in applicationContextLoaded(), it works. But if I comment it out, letting [Autowired] do its job, adminService is never initialized.

    Did I miss something?

  • #2
    Hi Sebastien,

    have you tried placing the metadata above the accessors for the adminservice instead of the private variable?

    regards,
    Christophe

    Comment


    • #3
      I just did. And it doesn't work either.

      By the way, I also added -keep-as3-metadata "Autowired" to my compiler options, but it didn't work either.

      Comment


      • #4
        Ok, I remember we had issues with autowiring the application view or main view component with 0.8.1.

        Can you this try with the 0.9-SNAPSHOT? Please note that we have disabled view-autowiring by default now to enhance performance. In order to enable it, you need to configure a stage processor in the application context.

        Code:
        <object id="defaultAutowiringStageProcessor" class="org.springextensions.actionscript.stage.DefaultAutowiringStageProcessor"/>
        regards,
        Christophe

        Comment


        • #5
          I'll try with 0.9-SNAPSHOT. Where can I download it with dependencies?

          Comment


          • #6
            Oops. I just found out about yaloo repositories. It's OK. I got 0.9-SNAPSHOT. I just tried it and I have the same symptoms. adminService is null when I call it (datagrid's creation complete)

            Comment


            • #7
              I've tried to put my service call in a button click event instead of the datagrid's creationComplete event, to see if the problem had to do with the service being called before it was autowired. But it's not. When I debug, I have the following log, indicating that "admin" has been processed (it's the name of my root application) but adminService is not autowired for some reason:

              Code:
              Tue Feb 2 14:53:18 GMT+0100 2010 DEBUG - org.springextensions.actionscript.context.support.XMLApplicationContext - Loading object definitions
              Tue Feb 2 14:53:18 GMT+0100 2010 INFO - org.springextensions.actionscript.context.support.XMLApplicationContext - Loading XML object definitions from [applicationContext.xml]
              Tue Feb 2 14:53:19 GMT+0100 2010 DEBUG - org.springextensions.actionscript.context.support.AbstractApplicationContext - No IObjectFactoryResourceLoader found.
              Tue Feb 2 14:53:19 GMT+0100 2010 DEBUG - org.springextensions.actionscript.context.support.AbstractApplicationContext - Done loading resources.
              Tue Feb 2 14:53:19 GMT+0100 2010 DEBUG - org.springextensions.actionscript.context.support.AbstractApplicationContext - Post processing object factory with post-processor '[object StageProcessorFactoryPostprocessor]'
              Tue Feb 2 14:53:19 GMT+0100 2010 INFO - org.springextensions.actionscript.ioc.factory.support.DefaultListableObjectFactory - Pre-instantiating '2' singletons in '[object FlexXMLApplicationContext]': channelSet,adminService
              Tue Feb 2 14:53:19 GMT+0100 2010 WARN - org.as3commons.reflect.Type - The class with the name 'ChannelSet.as$136::AuthenticationAgent' could not be found in the application domain '[object ApplicationDomain]'
              Tue Feb 2 14:53:19 GMT+0100 2010 WARN - org.as3commons.reflect.Type - The class with the name 'ChannelSet.as$136::AuthenticationAgent' could not be found in the application domain '[object ApplicationDomain]'
              Tue Feb 2 14:53:19 GMT+0100 2010 DEBUG - org.springextensions.actionscript.ioc.factory.support.DefaultListableObjectFactory - Singleton instantiated: 'channelSet'
              Tue Feb 2 14:53:19 GMT+0100 2010 DEBUG - org.springextensions.actionscript.ioc.factory.support.DefaultListableObjectFactory - Singleton instantiated: 'adminService'
              Tue Feb 2 14:53:19 GMT+0100 2010 DEBUG - org.springextensions.actionscript.stage.FlexStageProcessorRegistry - Stage processing starting with component '[object _admin_mx_managers_SystemManager]'
              Tue Feb 2 14:53:19 GMT+0100 2010 DEBUG - org.springextensions.actionscript.stage.FlexStageProcessorRegistry - Stage processing completed
              Tue Feb 2 14:53:19 GMT+0100 2010 DEBUG - org.springextensions.actionscript.stage.FlexStageProcessorRegistry - FlexStageProcessorRegistry was initialized
              Tue Feb 2 14:53:19 GMT+0100 2010 DEBUG - org.springextensions.actionscript.stage.FlexStageProcessorRegistry - Process UIComponent 'admin'
              TypeError: Error #1009: Il est impossible d'accéder à la propriété ou à la méthode d'une référence d'objet nul.

              Comment


              • #8
                Hi Sebastien,

                this is very strange. Is it possible to post some code so we can debug this? Are you using the mx or spark components? Have you tried autowiring something in a subcomponent of the application?

                regards,
                Christophe

                Comment


                • #9
                  I wanted to post some code so I tried to reproduce the problem in a smaller application but then when I launched the application, the Flash player gave me a runtime error saying it could not find class org.springextensions.actionscript.stage.DefaultAut owiringStageProcessor
                  So I read the documentation and forced Flex compiler to include this class and then it worked. I could not reproduce my problem. So I forced the inclusion of the same class in my original application and it worked there as well.

                  Now it works when I call the service from a button click. But when I call it from the application creationComplete, the service has not been autowired yet. For now, I added my service call in adminService setter, but it's not very clean. How can I make it so that my service is called AFTER it has been autowired? Is there an event for that?

                  Comment


                  • #10
                    Hi Sebastien,

                    good to hear that it is working now.

                    There is no event currently that informs you when something has been autowired. If you don't want to invoke the service in the setter, you can observe its value with BindingUtils.bindSetter() and invoke the service in a separate handler.

                    If you think having an event dispatched when a property is autowired would be useful, please file an enhancement requests in the Jira.

                    regards,
                    Christophe

                    Comment


                    • #11
                      Done: http://jira.springframework.org/brow...IONSCRIPTAS-87

                      Comment

                      Working...
                      X