ActiveObjects: java.lang.reflect.InvocationTargetException

Kinto Soft
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 24, 2013

Hi,

I got an active object reference by using:

ao = ComponentAccessor.getOSGiComponentInstanceOfType(ActiveObjects.class);

but when I try to ise it:

ao.find(<Some class>);

a java.lang.reflect.InvocationTargetException is thrown.

Any idea?

Thanks,

Pablo.

1 answer

1 accepted

1 vote
Answer accepted
Jobin Kuruvilla [Adaptavist]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 24, 2013

ActiveObjects can only be initialized using constructor injection.

Kinto Soft
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 24, 2013

The problem is that the object receiving the injected ActiveObject is a spring bean, so all its initialization parameters must be declared in the spring context (META-INF/spring/context.xml) and I am unable to configure ActiveObjects with Spring. Any suggestion?

Kinto Soft
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 24, 2013

Hi Jobin, I've also read this interesting article from you:

http://www.j-tricks.com/1/post/2012/07/active-objects-injection.html

But I still face the same problem: If I use the JTricksManagerImpl to get a valid reference to the ActiveObject instance, that should also be declared in the spring context:

public class X{

 private ActiveObject ao;

 public X(JTricksManager trick){

	ao = trick.getActiveObjects();

  }

}

In the spring context...

<beans:bean id="foo" class="X">
    <beans:constructor-arg index="1" ref="trick" />	
</beans:bean>

And the trick reference should also be included in the context:

<beans:bean id="trick" class="com.jtricks.manager.JTricksManagerImpl">
   <beans:constructor-arg index="1" ref="ActiveObject?????" />	
</beans:bean>

Pablo.

[Edited]

I've guess I did not get the point from your article:

if (this.jTricksManager == null)
this.jTricksManager = ComponentAccessor.getOSGiComponentInstanceOfType(JTricksManager.class);

It looks like I do not need to inject the JtricksManager object.

I'll try your solution!

Kinto Soft
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 24, 2013

FYI,

ComponentAccessor.getOSGiComponentInstanceOfType(JTricksManager.class);

it always returns NULL.

Kinto Soft
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 25, 2013

Ok. Thank you! mainly because this great article:

http://www.j-tricks.com/1/post/2012/07/active-objects-injection.html

Finally, it worked for me.

if (this.jTricksManager == null)
this.jTricksManager = ComponentAccessor.getOSGiComponentInstanceOfType(JTricksManager.class);

it was returning always null becuase it must be called after the spring context is fully initialized, so the problem was in calling it from inside a bean constructor.

Now, I let the bean fully initialize and get the active object reference just before it is going to be used.

Thanks,

Pablo

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events