• 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 ...
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Piet Souris
  • salvin francis
  • Stephan van Hulst
  • Frits Walraven
  • Carey Brown
  • Jj Roberts

autowire spring bean in a regular pojo which is not spring bean

Ranch Hand
Posts: 123
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello All,
a quick question.
i have a class which holds a hashmap.

public class PhotoTypeMapper {
private Map<String,String> photoTypeMap;

In the spring config i initilize the map
<bean id="photoTypeMapper" class="com.XXX.services.PhotoTypeMapper">
<property name="photoTypeMap">
<entry key="TDS">
<entry key="ETS">
<entry key="INP">

i have a regular class for example Test this and this is just a regular class how can i autowire my mapper class in this i tried.
class Test{

private PhotoTypeMapper photoTypeMapper;
when i check i get photoTypeMapper as null since the class Test is not a spring bean.

Any shortcuts how to achive this, i can always use the ClassPathApplicationContext and manullay get the bean just is there a way to autowire it.


Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Autowired annotation is used in wrong way.

As in your this is a bean so to test this bean. Added getter and setter to the property photoTypeMap in your pojo.
in your XML file You have already defiened the bean so need for annotations remove all annotations.

In the test Class get the the bean.

Please use code Tags...Just edit your code and use Code tags
This will take every ounce of my mental strength! All for a tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
    Bookmark Topic Watch Topic
  • New Topic