Basic question using Autowired

7 views
Skip to first unread message

Jorge

unread,
Feb 21, 2011, 12:41:41 PM2/21/11
to springactionscript-dev
Hi everyone!
I'm starting using spring AS, and doing my first steps, i found my
first problem.
I'm trying to autowire an attribute of my class, but it didnt work.
So, I dont know if I'm missing something, if this feature is not
available or if i misunderstood something.
Here is the code so you can get a better idea.

This is my application-context.xml

<?xml version="1.0" encoding="utf-8"?>
<objects>
<object id="myObject" class="IoCClass">
<property name="text" value="Hellooo" />
</object>
</objects>

This is the injected class:

package
{
public class IoCClass
{
public var text:String;

public function IoCClass()
{
}

public function getAText():String{
return text;
}
}
}

This is the autowired class:

package
{
import mx.containers.Canvas;

public class OtherClass extends Canvas
{
[Autowired]
private var myObject:IoCClass;

public function OtherClass()
{
}

public function text():String{
return myObject.getAText() + " added by OtherClass";
}
}
}

And this where I use all together:

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955"
minHeight="600"
applicationComplete="this.init()">

<fx:Script>
<![CDATA[
import
org.springextensions.actionscript.context.support.XMLApplicationContext;


private var applicationContext:XMLApplicationContext = new
XMLApplicationContext();

private function init():void{
var i:IoCClass;
applicationContext.addConfigLocation("application-context.xml");
applicationContext.addEventListener(Event.COMPLETE,
handleComplete);
applicationContext.load();
}

private var otherClass:OtherClass = new OtherClass();

private function handleComplete(event:Event):void{
this.someText.text = otherClass.text();
}
]]>
</fx:Script>
<s:Label id="someText" />
</s:Application>

The code is pretty simple, as you can see, but when i send the message
text() to my OtherClass object, i get a null pointer in the myObject
inst. var. What i expect is that this var, myObject, would be injected
by using autowired... am i missing something?
BTW, i just added the compiler arguments: -keep-as3-metadata
"Autowired"
Thank you very much for your help.
Cheers,
Jorge

Roland Zwaga

unread,
Feb 21, 2011, 5:39:44 PM2/21/11
to springactio...@googlegroups.com
hi there,

the property you´re trying to autowire is private, only public members
can be autowired.

hope that helps :)

cheers,

Roland

> --
> You received this message because you are subscribed to the Google
> Groups "springactionscript-dev" group.
> To post to this group, send email to springactio...@googlegroups.com.
> To unsubscribe from this group, send email to
> springactionscrip...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/springactionscript-dev?hl=en.
>
>

Jorge Silva - 10Pines

unread,
Feb 21, 2011, 9:36:30 PM2/21/11
to springactio...@googlegroups.com, Roland Zwaga
Hi Roland!
Thanks for the answer.
I just tried with public member, but same behavior... any other clue?
I'm really disappointed about my programmer skills... :(
Thanks in advance!
Jorge
--

Jorge Silva
Agile Software Development
Mobile: +54 - 11 - 6336 - 3360
email: jsi...@10Pines.com
site: http://www.10Pines.com



Radu Cocieru

unread,
Feb 22, 2011, 3:58:20 AM2/22/11
to springactio...@googlegroups.com
Hi Jorge

Did you include the keep metadata in the command line arguments ?

If not Add this to your command line arguments.

-keep-as3-metadata+=Autowired 

Regards.


Radu Cocieru

Roland Zwaga

unread,
Feb 22, 2011, 4:18:29 AM2/22/11
to springactio...@googlegroups.com
Hey Jorge,

this is also your problem:


private var otherClass:OtherClass = new OtherClass();

You shouldn't instantiate a wired class like this, either you define
it in the XML configuration or declare the component in your MXML.

Did you thoroughly read the documetnation at
http://www.springactionscript.org/docs/reference/html/springactionscript.html
?

I suggest you work through that, as the questions you've been asking
are pretty well covered there.
If you have any more questions afterwards I suggest you move your
questions to the springactionscript forum:

http://forum.springframework.org/forumdisplay.php?f=60

This list is actually aimed at people who are developing the spring
actionscript library itself, not at users of the library. The forum is
always the best place for questions like the ones you have.

good luck.

Roland

>> **
>>
>> *Jorge Silva*


>> Agile Software Development
>> Mobile: +54 - 11 - 6336 - 3360
>> email: jsi...@10Pines.com

>> site: http://www.10Pines.com <http://www.10pines.com/>
>>
>> * <http://www.10pines.com/>*


>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "springactionscript-dev" group.
>> To post to this group, send email to
>> springactio...@googlegroups.com.
>> To unsubscribe from this group, send email to
>> springactionscrip...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/springactionscript-dev?hl=en.
>>
>
>
>
> --
> Radu Cocieru
>

Andrew Lewisohn

unread,
Feb 22, 2011, 11:30:00 AM2/22/11
to springactionscript-dev
Jorge,

Checking out the forums is typically the best way to go, but as a
quick note, I don't see a declaration in your application context for
an autowiring processor. This line should appear in your context to
enable metadata processing of the Autowired annotation:

<object id="autowiringStageProcessor"
class="org.springextensions.actionscript.stage.DefaultAutowiringStageProcessor"/
>

Hope that helps.

-Andy

On Feb 22, 4:18 am, Roland Zwaga <s...@dds.nl> wrote:
> Hey Jorge,
>
> this is also your problem:
> private var otherClass:OtherClass = new OtherClass();
>
> You shouldn't instantiate a wired class like this, either you define  
> it in the XML configuration or declare the component in your MXML.
>
> Did you thoroughly read the documetnation at  http://www.springactionscript.org/docs/reference/html/springactionscr... 
> ?
>
> I suggest you work through that, as the questions you've been asking  
> are pretty well covered there.
> If you have any more questions afterwards I suggest you move your  
> questions to the springactionscript forum:
>
> http://forum.springframework.org/forumdisplay.php?f=60
>
> This list is actually aimed at people who are developing the spring  
> actionscript library itself, not at users of the library. The forum is  
> always the best place for questions like the ones you have.
>
> good luck.
>
> Roland
>
>
>
>
>
>
>
> > Hi Jorge
>
> > Did you include the keep metadata in the command line arguments ?
>
> > If not Add this to your command line arguments.
>
> > -keep-as3-metadata+=Autowired
>
> > Regards.
>
> > On Tue, Feb 22, 2011 at 4:36 AM, Jorge Silva - 10Pines
> > <jsi...@10pines.com>wrote:
>
> >> Hi Roland!
> >> Thanks for the answer.
> >> I just tried with public member, but same behavior... any other clue?
> >> I'm really disappointed about my programmer skills... :(
> >> Thanks in advance!
> >> Jorge
>

Jorge Silva - 10Pines

unread,
Feb 22, 2011, 10:39:07 AM2/22/11
to springactio...@googlegroups.com, Roland Zwaga
Roland, two things:
1. Yeah! You're right, this is a misconception about container from my side. I shouldn't instantiate a wired class...
2. I was reading the documentation to do my first step, but i was stucked in this issue. Now I will go back there.
3. Sorry for sending the question here, I thought this was for Spring AS user. 

Thank you very much for the support!
Jorge

Jorge Silva

Reply all
Reply to author
Forward
0 new messages