tags:

views:

23

answers:

1

We work with a web application and autowire beans using WebApplicationContextUtils in the init method.

Could you clarify some details about bean initialization?

The question rises from the static factory method.

Suppose there's a bean that is created in a static factory method.

As we can see, when the web app is deployed, the ContextLoaderListener initializes all the beans present

in Spring xml config file.

Now happens such a thing. In the static factory method we run a timer that starts ticking.

But in reality we wouldn't want it to start ticking unless the bean is injected into a property of the object !

That is question number one - all the beans are automatically initialized on deploy - correct?

And after that when we need an injection, it simply feels the link with the address of the object created during initialization, though OBJECT WAS CREATED ON WEB APP DEPLOY, immediately ! (I assume the default singleton-creation Spring behavior)

Second question: are all copies of a web app use the same beans, so all beans are WEB-APP wide, every Spring bean is shared between all the copies of this web app running?

+1  A: 

That is question number one - all the beans are automatically initialized on deploy - correct?

Unless you enable some sort of lazy-loading, then yes.

Second question: are all copies of a web app use the same beans, so all beans are WEB-APP wide, every Spring bean is shared between all the copies of this web app running?

I think there is some confusion here about what a "copy of a webapp" means. Do you mean that you are deploying the same web application (code and files) to an app server under multiple context paths? i.e., deploying your webapp project as webappCopy1, webappCopy2, webappCopy3, etc? If so, then each application is isolated and creates it's own separate bean factory.

matt b
@matt b No, I mean just one web app and different sessions running on this ONE web app, let's say call it http://localhost/UniqueWebApp
EugeneP