1

I'm creating beans with the following property

  <property name="classe">
     <value type="java.lang.Class">foo.bar.SomeClass</value>
  </property>

The property "classe" is of type Class.

just like someone hinted on the following question : Spring syntax for setting a Class object?

The problem is that I'm having this exception when deploying my application :

java.lang.ClassNotFoundException: java/lang.Class
at weblogic.utils.classloaders.GenericClassLoader.findLocalClass(GenericClassLoader.java:280)
at weblogic.utils.classloaders.GenericClassLoader.findClass(GenericClassLoader.java:253)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
at weblogic.utils.classloaders.GenericClassLoader.loadClass(GenericClassLoader.java:177)
at org.springframework.util.ClassUtils.forName(ClassUtils.java:229)
at org.springframework.beans.factory.config.TypedStringValue.resolveTargetType(TypedStringValue.java:154)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveTargetType(BeanDefinitionValueResolver.java:196)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:163)

It looks like Steve B. in the question I linked had the same problem and it was related to some spring configuration. I'm very new to spring and dont really know how to fix this.

Thanks in advance for your answers.

6
  • 4
    What about simply <property name="classe" value="foo.bar.SomeClass"/>? Spring should figure out the correct type based on classe property type, which is java.lang.Class. Commented Feb 27, 2012 at 12:06
  • @Tomasz It actually tries to convert it to java.lang.String : org.springframework.beans.TypeMismatchException: Failed to convert property value of type [java.lang.String] to required type [java.lang.Class] for property 'classe' Commented Feb 27, 2012 at 12:32
  • 2
    Which version of Spring are you using? I just successfully tested it with Spring 3.1, but I'm pretty sure it works with Spring 3.0/2.5.x as well. Commented Feb 27, 2012 at 12:40
  • 1
    @TomaszNurkiewicz I'm using Spring 2.0, your solution worked, I just realized I made a mistake while typing. Can you post your solution as an answer so I can mark this post as Answered and upvote you ? Commented Feb 27, 2012 at 13:15
  • Please post the code of the setter. Commented Feb 27, 2012 at 13:21

1 Answer 1

1

What about simply:

<property name="classe" value="foo.bar.SomeClass"/>

Spring should figure out the correct type based on classe property type, which is java.lang.Class. I just successfully tested it with Spring 3.1, but I'm pretty sure it works with Spring 3.0/2.5.x as well.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.