Announcement Announcement Module
Collapse
No announcement yet.
Adding an instance at runtime to an ApplicationContext Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Adding an instance at runtime to an ApplicationContext

    I'm looking to add an instance I only have access to at runtime to my Spring XMLApplicationContext. Is there a way to do this? I can only obtain a reference to this value at runtime, I can't instantiate it myself.

    I am aware that I could use an intermediate class and instantiate it in my XML file then populate a property of it when the application context has been loaded, but I would prefer to do this before everything is loaded so when autowiring happens, everything is ready for my application.

  • #2
    indeed possible

    Hi there,

    this is indeed possible, use the registerSingleton method for that:

    Code:
    xmlApplicationContext.registerSingleton("objectName", objectInstance);
    Hope that helps,

    cheers,

    Roland

    Comment


    • #3
      Thanks a bunch, I must have missed that method! Keep up the great work guys!

      Comment


      • #4
        Weird, there seems to be a little bug when adding a certain DisplayObject to the applicationContext. I'm using SA in a JW Player Plugin, and evidently trying to set the "name" property on a timeline object results in a runtime error:

        Code:
        An ActionScript error has occurred:
        Error: Error #2078: The name property of a Timeline-placed object cannot be modified.
        	at flash.display::DisplayObject/set name()
        	at org.springextensions.actionscript.ioc.factory.config::PropertyPlaceholderConfigurer/resolvePropertyPlaceholdersForInstance()[C:\Resources\Flex\spring-actionscript-trunk\spring-actionscript-core\src\main\actionscript\org\springextensions\actionscript\ioc\factory\config\PropertyPlaceholderConfigurer.as:302]
        	at org.springextensions.actionscript.ioc.factory.config::PropertyPlaceholderConfigurer/postProcessObjectFactory()[C:\Resources\Flex\spring-actionscript-trunk\spring-actionscript-core\src\main\actionscript\org\springextensions\actionscript\ioc\factory\config\PropertyPlaceholderConfigurer.as:135]
        	at org.springextensions.actionscript.ioc.factory.config.flex::FlexPropertyPlaceholderConfigurer/postProcessObjectFactory()[C:\Resources\Flex\spring-actionscript-trunk\spring-actionscript-core\src\main\actionscript\org\springextensions\actionscript\ioc\factory\config\flex\FlexPropertyPlaceholderConfigurer.as:142]
        	at org.springextensions.actionscript.context.support::AbstractApplicationContext/doInvokeObjectFactoryPostProcessors()[C:\Resources\Flex\spring-actionscript-trunk\spring-actionscript-core\src\main\actionscript\org\springextensions\actionscript\context\support\AbstractApplicationContext.as:362]
        	at org.springextensions.actionscript.context.support::AbstractApplicationContext/invokeOrderedObjectFactoryPostProcessors()[C:\Resources\Flex\spring-actionscript-trunk\spring-actionscript-core\src\main\actionscript\org\springextensions\actionscript\context\support\AbstractApplicationContext.as:322]
        	at org.springextensions.actionscript.context.support::AbstractApplicationContext/invokeObjectFactoryPostProcessors()[C:\Resources\Flex\spring-actionscript-trunk\spring-actionscript-core\src\main\actionscript\org\springextensions\actionscript\context\support\AbstractApplicationContext.as:310]
        	at org.springextensions.actionscript.context.support::AbstractApplicationContext/resourceLoadQueue_completeHandler()[C:\Resources\Flex\spring-actionscript-trunk\spring-actionscript-core\src\main\actionscript\org\springextensions\actionscript\context\support\AbstractApplicationContext.as:398]
        	at flash.events::EventDispatcher/dispatchEventFunction()
        	at flash.events::EventDispatcher/dispatchEvent()
        	at org.springextensions.actionscript.core.operation::AbstractOperation/dispatchCompleteEvent()[C:\Resources\Flex\spring-actionscript-trunk\spring-actionscript-core\src\main\actionscript\org\springextensions\actionscript\core\operation\AbstractOperation.as:238]
        	at org.springextensions.actionscript.core.operation::OperationQueue/operation_completeHandler()[C:\Resources\Flex\spring-actionscript-trunk\spring-actionscript-core\src\main\actionscript\org\springextensions\actionscript\core\operation\OperationQueue.as:122]
        	at flash.events::EventDispatcher/dispatchEventFunction()
        	at flash.events::EventDispatcher/dispatchEvent()
        	at org.springextensions.actionscript.core.operation::AbstractOperation/dispatchCompleteEvent()[C:\Resources\Flex\spring-actionscript-trunk\spring-actionscript-core\src\main\actionscript\org\springextensions\actionscript\core\operation\AbstractOperation.as:238]
        	at org.springextensions.actionscript.core.operation::OperationQueue/operation_completeHandler()[C:\Resources\Flex\spring-actionscript-trunk\spring-actionscript-core\src\main\actionscript\org\springextensions\actionscript\core\operation\OperationQueue.as:122]
        	at flash.events::EventDispatcher/dispatchEventFunction()
        	at flash.events::EventDispatcher/dispatchEvent()
        	at org.springextensions.actionscript.core.operation::AbstractOperation/dispatchCompleteEvent()[C:\Resources\Flex\spring-actionscript-trunk\spring-actionscript-core\src\main\actionscript\org\springextensions\actionscript\core\operation\AbstractOperation.as:238]
        	at org.springextensions.actionscript.core.io.support::LoadPropertiesOperation/properties_completeHandler()[C:\Resources\Flex\spring-actionscript-trunk\spring-actionscript-core\src\main\actionscript\org\springextensions\actionscript\core\io\support\LoadPropertiesOperation.as:109]
        	at flash.events::EventDispatcher/dispatchEventFunction()
        	at flash.events::EventDispatcher/dispatchEvent()
        	at org.springextensions.actionscript.collections::Properties/LoaderComplete_handler()[C:\Resources\Flex\spring-actionscript-trunk\spring-actionscript-core\src\main\actionscript\org\springextensions\actionscript\collections\Properties.as:202]
        	at flash.events::EventDispatcher/dispatchEventFunction()
        	at flash.events::EventDispatcher/dispatchEvent()
        	at flash.net::URLLoader/onComplete()
        Just so you can be aware of the issue

        Comment

        Working...
        X