Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ref vs depends-on attributes in Spring

Tags:

java

spring

I am confused between ref and depends-on attribute in Spring.I read the spring doc but I am still confused.I wish to know the exact difference between the two and in which case which one shall be used.

like image 704
user1649415 Avatar asked Sep 30 '12 17:09

user1649415


People also ask

What is ref attribute in Spring?

Spring ref attribute The ref attribute is a shortcut to the <ref> tag, used to refer to other beans for injection.

Which attributes are applicable for an inner bean?

An inner bean definition does not require a defined id or name; if specified, the container does not use such a value as an identifier. The container also ignores the scope flag on creation: Inner beans are always anonymous and they are always created with the outer bean.

What is meant by dependencies in Spring?

Dependency Injection is a fundamental aspect of the Spring framework, through which the Spring container “injects” objects into other objects or “dependencies”. Simply put, this allows for loose coupling of components and moves the responsibility of managing components onto the container.


1 Answers

From the official documentation: http://docs.spring.io/spring/docs/3.2.x/javadoc-api/org/springframework/context/annotation/DependsOn.html

Beans on which the current bean depends. Any beans specified are guaranteed to be created by the container before this bean. Used infrequently in cases where a bean does not explicitly depend on another through properties or constructor arguments, but rather depends on the side effects of another bean's initialisation.

like image 91
Lyju I Edwinson Avatar answered Oct 24 '22 16:10

Lyju I Edwinson