Spring Framework

org.springframework.beans.factory.annotation
Annotation Type Autowired


@Target(value={CONSTRUCTOR,FIELD,METHOD})
@Retention(value=RUNTIME)
@Documented
public @interface Autowired

Marks a constructor, field, setter method or config method as to be autowired by Spring's dependency injection facilities.

Only one constructor (at max) of any given bean class may carry this annotation, indicating the constructor to autowire when used as a Spring bean. Such a constructor does not have to be public.

Fields are injected right after construction of a bean, before any config methods are invoked. Such a config field does not have to be public.

Config methods may have an arbitrary name and any number of arguments; each of those arguments will be autowired with a matching bean in the Spring container. Bean property setter methods are effectively just a special case of such a general config method. Such config methods do not have to be public.

In the case of multiple argument methods, the 'required' parameter is applicable for all arguments.

In case of a Collection or Map dependency type, the container will autowire all beans matching the declared value type. In case of a Map, the keys must be declared as type String and will be resolved to the corresponding bean names.

Note that actual injection is performed through a BeanPostProcessor which in turn means that you cannot use @Autowired to inject references into BeanPostProcessor or BeanFactoryPostProcessor types. Please consult the javadoc for the AutowiredAnnotationBeanPostProcessor class (which, by default, checks for the presence of this annotation).

Since:
2.5
Author:
Juergen Hoeller, Mark Fisher
See Also:
AutowiredAnnotationBeanPostProcessor, Qualifier, Value

Optional Element Summary
 boolean required
          Declares whether the annotated dependency is required.
 

required

public abstract boolean required
Declares whether the annotated dependency is required.

Defaults to true.

Default:
true

Spring Framework