• 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

Bean initialization in spring

 
Ranch Hand
Posts: 238
1
Eclipse IDE Fedora 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 trying to understand the bean creation mechanism in spring.I have a doubt regarding the same.I want to know that when do we get the bean object (assuming the bean configuration is done in the xml file xxx-servlet.xml)?Does it happens as soon as we load the xml file from the path?or does it happens when we call a method from BeanFactory interface(or ApplicationContext interface)?

Thanks...
 
Bartender
Posts: 1682
7
Android Mac OS X IntelliJ IDE Spring Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Assuming that the beans are eagerly loaded (the default) it will be created when the application context is initialized. The container will call interfaces on BeanFactory (and others) to create and initialize those beans as part of the initialization process.
 
Sudhanshu Mishra
Ranch Hand
Posts: 238
1
Eclipse IDE Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the reply.
But i still want to get one thing clear.What is really an application context?Who creates it?Do i have my beans created as soon as my xml files are loaded/read by container?

I would be grateful for the answers.
Thanks.
 
Rancher
Posts: 2759
32
Eclipse IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You probably want to pick up a book on Spring. It will go in much more detail. I reccommend Spring In Action. It explains how the application context is loaded and how beans are initialized and wired

To answer your question, if you have a standalone app that you want to use spring in, you have to load the application context from the main method yourself. So, in your main method you do something like this


This call starts the application context, loads the xml, parses the xml, creates the beans, initializes the beans before returning. Basically, the container and beans are loaded for you from the constructor

If you are writing a webapp using spring, generally, you add something like this in your web.xml



Basically, you declare a servlet of type org.springframework.web.servlet.DispatcherServlet to start on startup. This servlet will load the Application Context on startup. It will do exactly what your main method would do.
 
reply
    Bookmark Topic Watch Topic
  • New Topic