• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

Dependency injection with Wrapper classes  RSS feed

 
Ranch Hand
Posts: 92
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • 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 Java Spring
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Hi

You can try something like this



Regards
 
John McParland
Ranch Hand
Posts: 92
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • 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;



 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!