Beans created twice
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)
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.
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
Whats wrong here and how can i set up the web.xml to load the Beans only once?
thank you in advance
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).
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.
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.