Invalid property ‘cacheTarget’ of bean class [org.springframework.osgi.service.exporter.support.OsgiServiceFactoryBean]

Okay, so I’ve lost so much time on this incredibly stupid issue, and Google wasn’t of much help that I thought I’d blog about it as a memo for myself and for others.

here’s the setup : I’ve created an osgi bundle (using PDE new plugin wizard), created a class (implementing an interface) and tried to export it as an OSGi service using Spring DM.

I used Spring IDE tooling to generate my bundle’s context xml files (I tend to follow the Spring DM best practices in separating the bundle’s context in 2 xml files, one for the regular Spring setup, the other for OSGi interactions).

Anyway, the first xml file simply declares a Spring bean :

<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xsi:schemalocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

	<bean id="todoListsServiceImpl" class="org.dynaresume.blueprint.todo.service.impl.TodoListsServiceImpl"></bean>
</beans>

Whereas the second one simply exports that bean as an OSGi service :

<beans xmlns:osgi="http://www.springframework.org/schema/osgi" xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemalocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
	http://www.springframework.org/schema/osgi http://www.springframework.org/schema/osgi/spring-osgi-2.0-m1.xsd">

	<osgi:service ref="todoListsServiceImpl" interface="org.dynaresume.blueprint.todo.service.ITodoListsService">

</osgi:service></beans>

It can’t get simpler than this. Even worse, I’ve been working with OSGi and Spring DM on a rather big project at work for more than a year now, and yet, this simple example invariantly failed at runtime with this stacktrace :

927674 [SpringOsgiExtenderThread-5] ERROR org.springframework.osgi.extender.internal.activator.ContextLoaderListener – Application context refresh failed (OsgiBundleXmlApplicationContext(bundle=org.dynaresume.blueprint.todo.service.impl, config=osgibundle:/META-INF/spring/*.xml))
org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘org.springframework.osgi.service.exporter.support.OsgiServiceFactoryBean#0′: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property ‘cacheTarget’ of bean class [org.springframework.osgi.service.exporter.support.OsgiServiceFactoryBean]: Bean property ‘cacheTarget’ is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
[...]
at java.lang.Thread.run(Thread.java:619)
Caused by: org.springframework.beans.NotWritablePropertyException: Invalid property ‘cacheTarget’ of bean class [org.springframework.osgi.service.exporter.support.OsgiServiceFactoryBean]: Bean property ‘cacheTarget’ is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
[...]
… 18 more

This drove me mad for 3 days : I’ve tried many (stupid) things, like trying out different versions of Spring DM, or Spring (2.5.6[ε|.A|.SEC01]) to no avail.

But tonight, after coming back from a 4 days vacation, I was able to track down the cause of this issue : it’s caused by the usage of and old version of Spring DM’s osgi schema. If you look back at the second xml file’s source, you can see :

http://www.springframework.org/schema/osgi http://www.springframework.org/schema/osgi/spring-osgi-2.0-m1.xsd

This schema’s version declares a cache-target xml attribute, and while I didn’t use it in my xml, a default value was inferred and the Spring bean creation facility didn’t find it to it’s liking and thus the stacktrace listed above.

Simply changing the xsd to :

http://www.springframework.org/schema/osgi http://www.springframework.org/schema/osgi/spring-osgi-1.2.xsd

Fixes the issue.

I feel awful right now.
Based on Mirko’s comment, I’ve updated this post to specify the xsd schema to use instead of relying on the generic name.

Pascal and/or Angelo : if you read this, then you’ll understand that I won’t be able to finish the task we talked about in a week as I promised ! (and don’t you dare make fun of me, this kind of shit can happen to anybody :D)

About these ads

9 Responses to Invalid property ‘cacheTarget’ of bean class [org.springframework.osgi.service.exporter.support.OsgiServiceFactoryBean]

  1. Mirko Jahn says:

    Don’t worry, I had a similar problem when moving to from spring dm 1.0.2 to 1.1.2! Good you blogged about it, so hopefully others get lucky with google next time. The only drawback is that when you’re relying on the latest xsd, it might break in the future with the spring version you’re using in production. Too bad there are no version ranges for this kind of dependencies ;-)

    • jawher says:

      thanks Mirko for the comment.

      The only drawback is that when you’re relying on the latest xsd, it might break in the future with the spring version you’re using in production.

      Indeed ! Relying on a generic xsd name that might refer to a different schema in future versions is risky.
      I’ll update the post to reference the 1.2 version.

  2. charles says:

    thanks a lot solved my problem !

  3. Luana says:

    Thank you!!!!!!!!!!
    You helped me :D

  4. Jahroots says:

    Thanks a lot, it solved my problem ;)

  5. Roadrunn says:

    Big thanks! This blog entry is the single thing that google finds about that error! Your pos just saved my day :)

  6. sjain says:

    I have two module & didn’t define version in any one. I have successfully installed one module but other showing the same exception.
    working on virgo web server
    any help ..

    thanks

  7. sjain says:

    I too have tried what u suggested but its not working :(

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: