Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Bean Inheritance - Scope, autowire, depends-on, etc

Tags:

spring

From Spring documentation http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/beans.html#beans-child-bean-definitions:

The remaining settings are always taken from the child definition: depends on, autowire mode, dependency check, singleton, scope, lazy init.

I think there is a good reason for not inheriting these settings, but can't think of one. What are the reasons?

like image 916
user816513 Avatar asked Nov 04 '22 19:11

user816513


1 Answers

I think it's because it would cause more confusion. Imagine the time spent debugging why your bean is not in the default (singleton) scope. Or the case when the child bean is injected into a bean that the parent depends-on. You will get a circular dependency without being able to notice it.

Bean inheritance is only in terms of properties injected, and not in terms of bean settings.

like image 134
Bozho Avatar answered Nov 12 '22 19:11

Bozho