• 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
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

Dependency injection with Wrapper classes

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

I am fairly new to Spring and decided to use the little I'd learned about dependency injection to experiment!

However I cannot seem to configure/code spring to inject bean properties of wrapper classes, e.g. Double. See this;

Code;


Main class


Spring config


When I run this, I get the following exception;



Any ideas? Is it possible to inject wrapper types as properties?

Thanks,

John
 
John McParland
Ranch Hand
Posts: 92
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Typical, the second I post it, I find the bug!

The declaration of


was changed to;



note the use of Double rather than double.

So this brings me to a second, similar problem. I have an interface;



an implementing class;



a main class



and a Spring config;



But when I try to run (e.g. java com.mcparland.john.conversion.ConverterApp 7) I get the following exception;



I cannot understand what the problem is in this case. Can anyone help?

Thanks,

John
 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

You can try something like this



Regards
 
John McParland
Ranch Hand
Posts: 92
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Lino, that worked!

What I don't quite understand now is why the second example required me to use;



when the first example required just;



The only real difference I can see between the class definitions is the first implements an interface with a generic type to use Double, the second uses the Double type explicitly.


Snippets of both classes;



 
reply
    Bookmark Topic Watch Topic
  • New Topic