• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Wiring Properties collection not working

 
Ranch Hand
Posts: 367
Eclipse IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I'm testing the Spring 3.1 wiring in the Properties collection, had no problem with Map & Collection.

For Properties, I had to use Enumeration for iteration purpose, don't know if there is any other way to iterate over Properties.

This is the xml configuration file :


And this is the Saxophone class : -


I'm getting this error :-


As Saxophone implements the Instrument interface, all references of Saxophones passed into the hank bean should be of type Instrument but the error points out that <props> element are still in String.
How to override it ? I implemented Map and Collection and had no problem with them. The change in the bean name from GUITAR to guitar or guitara has no effect on the error message.
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First a Properties is always a String value.

someKey=someStringValue

For looping through properties, would be the same as a map. there is a values() method on Properties

so

for (String someValue : props.values() {
}

Mark
 
pramod talekar
Ranch Hand
Posts: 367
Eclipse IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Mark,

Thanks for your reply.
But Looping was never a problem in the below code.
Enum is working fine but I need to know how to make GUITAR and HARMONICA appear as of type Instrument to the jvm for conversion.
If Property elements are always going to remain as String then what is work around for this error message ?
 
pramod talekar
Ranch Hand
Posts: 367
Eclipse IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Mark,

I did as per your suggestions.



I get

Can not convert element type from Object to String

for the 'for' statement i.e. instruments.values().

 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A properties key and value are always always String.

Think of a Properties class as a Map<String, String>

so no matter what you will never get an Instrument.

Mark
 
pramod talekar
Ranch Hand
Posts: 367
Eclipse IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Right Mark.

So how to do autowiring for Properties.
 
Ranch Hand
Posts: 66
VI Editor Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I understand you want to wire Enums into your Spring context. In which case, you might want to take a look at:
http://www.alanbarrows.co.uk/api/article/id/9/a/Spring-context-and-Enums and may be this: http://forum.springsource.org/showthread.php?19696-Spring-1-2-3-How-do-I-inject-Java-1-5-Enums
 
pramod talekar
Ranch Hand
Posts: 367
Eclipse IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Prabaharan.
You guessed it right.
 
Please do not shoot the fish in this barrel. But you can shoot at this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic