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

  • Spring container in web application - looking for beans.

    Hello

    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:

    Code:
    INFO : org.springframework.beans.factory.support.DefaultListableBeanFactory - Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@1172fb9:
    and there goes a long list of beans, like:
    Code:
    org.springframework.security.filterChains
    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
    Code:
    <context:component-scan base-package="package.to.scan" />
    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
    Code:
    <context:component-scan base-package="pl.meble.taboret" />
    I am getting
    Code:
    org.springframework.beans.factory.support.DefaultListableBeanFactory@1172fb9:
    listed twice, like Spring is loading beans twice.

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

    EDIT:
    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, 06:43 AM.

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

    Just a thought.

    Jeff

    Comment


    • #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.

      Jeff

      Comment

      Working...
      X