Announcement Announcement Module
No announcement yet.
Spring container in web application - looking for beans. Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring container in web application - looking for beans.


    I have one question about Spring way of finding and initializing beans.

    In my web application that is deployed to Tomcat 7.0 most of the beans are annotated with @Component annotation, so we don't have so much xml code.

    During the startup of Tomcat I can see a message:

    INFO : - Pre-instantiating singletons in[email protected]:
    and there goes a long list of beans, like:
    and others from Spring, but among them I can see the names of the classes that I annotated with @Component.

    After those information I am getting info about mapping methods to URLs.

    As far as I understand Spring configuration, it knows where to look for beans because I put
    <context:component-scan base-package="" />
    in my .xml configuration file.

    But if I remove this line from the configuration file I am still getting this line about DefaultListableBeanFactory and list of beans,

    Interesting thing is, that if I don't remove
    <context:component-scan base-package="pl.meble.taboret" />
    I am getting
    Code:[email protected]:
    listed twice, like Spring is loading beans twice.

    Apart from
    <context:component-scan base-package="pl.meble.taboret" />
    how is it possible to point packages for Spring container to scan for beans?

    Sorry for all the fuss, it seems I had component-scan in two .xml files, so that is why beans were loaded twice.
    Last edited by AdWeed; Aug 8th, 2012, 05:43 AM.

  • #2
    Is logging output hitting your console twice perhaps?

    Just a thought.



    • #3
      You could peak at the beans within your applicationContext.

      Query the beanFactory within your applicationContext to see what is being loaded:

      Assuming you have access to applicationContext you could do:
      ctx.getBeanFactory().getBeanDefinitionCount() <== returns the number of beans defined in the factory.
      ctx.getBeanFactory().getBeanDefinitionNames() <== return the names of all beans defined in this factory.