The core of spring is Dependency injection (DI), and dependency injection is based on the configuration of dependent information, which is called metadata. In previous studies, the XML-based configuration has been used, and these metadata configurations are registered within spring as beandefinition,spring to create bean and injection dependencies for the template.
Starting with Spring 2.0, Spring adds support for annotation-type metadata configurations in turn. Since then we have another way of configuring beans. Spring contains many kinds of annotations, such as our familiar @autowired, @Compoent, and some unfamiliar such as @inject @Improt.
Classification
Spring contains so many annotations that the beginner is intimidated by them, and some of them are blurred. Therefore, spring annotations can be categorized. The core of spring's XML metadata configuration is the bean definition, its properties, and its dependent configuration, so you can also divide the spring annotations from this perspective into the following, first, see:
This article first to these comments to do a simple comb, and then in the subsequent article, for the following three kinds of more detailed description.
Category Overview
Below is a little more detailed description of each category, and a list of the most spring-supported annotations.
Container level
The container level refers to the annotations used to configure the spring container, which corresponds to the Springxml configuration file, as
@Configuration function on class, where many beans can be defined
@Import introduce additional configuration
@ComponentScan Auto-scan bean component configuration, and use with configuration
Bean level
The bean level refers to the object (class or method) that is annotated, and a beandefinition,spring is registered with the spring container to create the bean instance.
@component it and other annotated annotations, such as @service, function on a class, you can define a bean
@Named similar to the above, from JSR-330
Use @Bean with @configuration or @component
Bean attribute Level
This category refers to properties that act on the bean, such as whether to delay loading, scope, etc.
@Qualifier and @autowired
@Lazy Lazy Loading
@Scope define the Scope of the bean
@Required can be labeled on the set method, indicating that this method needs to be executed, otherwise run out of exception, long and @autowired with the use of
@PostConstruct [email protected] from the JSR, acting on the life cycle
Dependency level
Spring can use these annotations for dependency injection, usually automatically, or with some ancillary information.
@autowired automatic Dependency Injection in several ways, bytype,byname, etc., usually with @ qualifier
@Inject from JSR-330, similar to the above, JSR-330 related annotations
@Resource similar to the above, JSR-250 related annotations
@Value Primitive Type Injection
Summarize
The above simple description of the following spring support annotations and its basic role, but so far is a paper, but the spring annotation to establish a general impression is still more important. It is important to note that spring annotations and XML configuration are mutually reinforcing, each with its own merits and demerits, and in practice it is decided according to the actual situation. The next section will cover the details of this story.
Notes to Spring (i) overview