Announcement Announcement Module
No announcement yet.
Beans created twice Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Beans created twice

    Hi Everyone,

    i am getting crazy with following Problem and i struggle with this for 2 days now. I hope anyone can help me.

    I created a WebApplication based on following web.xml (i just changed some names)
    <?xml version="1.0" encoding="UTF-8"?>
    <web-app version="2.5" xmlns=""
    I run with this configuration for quite some time now, and i noticed that it seems that all my beans are created twice.Thats not problem for stateless beans, but i had to add a cache to a service bean and so, i just noticed the problem.

    Whats wrong here and how can i set up the web.xml to load the Beans only once?

    thank you in advance

  • #2
    And why do you think they are created twice?

    My guess, you are using classproxies and thus use cglib and haev logging in your constructor. This setup makes it that the constructor is called twice, once unproxied and second proxied. This MIGHT make it look like you have 2 instances.

    If not my guess is that you are importing files into your servicelayer-servlet.xml file or one of your a,b,c,d xml files is actually the servicelayer-servlet.xml file... (Changing names to something else doesn't really help here because you might have obscured the actual problem).
    Last edited by Marten Deinum; Aug 16th, 2010, 04:32 AM.


    • #3
      I added a breakpoint into an init method of a bean and noticed that it was called twice when the web application starts (i am using a BEA 10.3 Application Server)

      And one of the xml files is my servicelayer-service.xml file. The other xml files define some beans for quartz scheduling etc.

      I am not using cglib.
      Last edited by kajo; Aug 16th, 2010, 07:26 AM.


      • #4
        And hence your beans are loaded twice. Your servlet.xml shouldn't/mustn't be loaded by the contextloaderlistener. That is already being loaded by the DispatcherServlet. I suggest a read of the web chapter of the reference guide which explains that.