• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Error in spring context.xml

 
looka dicosta
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Every One,

I have class A with constructor argument as (URI uri, Image image), where URI is java.net.URI and Image is java.awt.Image. I am trying to configure it via spring as:



But error is thrown as : Exception in thread "main" org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'a' defined in class path resource [/context.spring.xml]: Unsatisfied dependency expressed through constructor argument with index 1 of type [java.awt.Image]: Could not convert constructor argument value of type [java.lang.String] to required type [java.awt.Image]: Failed to convert value of type 'java.lang.String' to required type 'java.awt.Image'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type [java.awt.Image]: no matching editors or conversion strategy found.

Please do provide your valuable suggestions.

Regards,
Looka
 
looka dicosta
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Any One ..Please Reply. Thanks in Advance
 
Darryl Burke
Bartender
Posts: 5148
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moced form Swing / AWT / SWT.

looka dicosta wrote:Any One ..Please Reply. Thanks in Advance

Please EaseUp <- link
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
value="" in your constructor-arg.

value = means you want ot pass in that value, that exact String value

value="something" means the string "something" will be passed in.

If you want to reference another bean you use ref="" instead of value=""

value is value, ref is ref.

Mark
 
looka dicosta
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Thanks Mark. But for image if I create another bean like .

and change the above as : .

Then also I am getting errors.
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, first you put

abstract="true"

This means that it is abstract and Spring will not create an object for you. Which means there is nothing to ref/inject in your other bean, hence an error.

You need would need to create a real Image instance if your constructor takes a class of that type. You can't pass a String for an Image, that is wrong types.

Mark

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic