• 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

Instantiated bean with private Constructor

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

I have created one bean with Default Private Constructor like below:



and i make its entry in applicationContext.xml, now when i run my server it run successfully and also instantiated my Test bean but i think it should give error as my constructor is Private.

Can you please tell me why it allows this scenerio?

Thanks
Gaurav
 
Ranch Hand
Posts: 265
Hibernate Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Gaurav,

This is explained in the Spring forums in this thread.

The short answer is that Spring is using reflection to set the constructor's accessibility to true for the purpose of instantiating it. The thread also explains why and how to use a security manager to override that behavior if you need to.
 
Gaurav Ram
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Again thank you very much sir for explaining me so well and giving me such a good link to study, that really helpful and open many windows of my mind and also removed many hidden queries.

Thanks again Sir,
Gaurav
 
reply
    Bookmark Topic Watch Topic
  • New Topic