Spring Creation and Unused Beans

I am working on a project that means customizing an existing application (JasperServer 3.7.1), which is implemented in Spring 2.5.6 (plus many other Spring frameworks).

The application consists of the applicationContext * .xml host containing bean definitions that, when connected to Spring, enliven the application - I think this is a typical Spring application configuration, as if this is my first experience using Spring, it seems that it is all well-written and follows a lot examples that I saw on the Internet and in books.

Since I am actually modifying an existing application by modifying beans as filterChainProxy (for example, we have our own security model), I am afraid to modify the actual configuration files that come with the product, instead, I might prefer to add additional appContext configuration files to existing ones override existing beans (i.e. leave the original configuration in tact as much as possible).

I managed to do this by creating a beans implementation of BeanFactoryPostProcessor, which, when initializing a pre-bean, allows me to modify the existing values โ€‹โ€‹of the / bean property of the user link. Everything seems to be working fine.

My query: let's say I had a bean with a property related to another bean, and my overrider bean changed this link to my own version of the bean, will Spring still create a bean that is no longer referenced? The reason is clearly that some of these unused beans may take up resources, which may be unwanted overhead.

Thank you in advance

+1
source share
1 answer

I'm not sure that I am following your example, but this may help clarify some things.

Typically, Spring will create a bean instance for each non-abstract definition of a bean in the context (this ignores objects such as non-single beans) areas, but I will ignore this for the purpose of this explanation). If multiple bean definition files are used, and some bean names are duplicated, then some definitions will be overridden by others. so far, so good, it looks like what you wanted.

After defining the bean definitions and any duplicate actions, then Spring will then instantiate the bean for each of these definitions. If you change the BeanA definition so that it no longer BeanB to BeanB , but instead BeanC to BeanC , but the BeanB definition still exists, then the BeanB will still be created even if it is not in use.

If this example does not reflect your question, please specify.

+1
source

All Articles