This article summarizes spring's commonly used annotations to make it easier for you to query and use, specifically as follows:
To turn on automatic scanning before using annotations
Where Base-package is the package (including the child package) that needs to be scanned.
<context:component-scan base-package= "Cn.test"/>
@Configuration take a class as an IOC container, and if it registers @bean on a method header, it acts as a Bean in this spring container.
@Scope annotation Scope
@Lazy (true) to indicate deferred initialization
@Service is used to label business layer components,
@Controller used to label the control layer component (such as action in struts)
The @Repository is used to annotate the data Access component, the DAO component.
@Component refers to components, we can use this annotation to annotate when components are not properly categorized.
@Scope used to specify the scope scope (used on a class)
@PostConstruct used to specify the initialization method (on method)
@PreDestory used to specify the method of destruction (used on methods)
@DependsOn: Define the order in which the bean is initialized and destroyed
@Primary: When multiple bean candidates appear when there is an automatic assembly, the Bean Annotated as @primary will be the preferred person, otherwise an exception will be thrown
@Autowired The default assembly by type, if we want to use by name assembly, can be used together with @qualifier annotations. As follows:
@Autowired @Qualifier ("Persondaobean") with multiple instances
@Resource is assembled by name by default, and a bean matching the name cannot be found until it is assembled by type.
@PostConstruct Initialization annotations
@PreDestroy destroy the note the default single instance starts on load
@Async an asynchronous method call, you need to add the following code:
<bean id= "Taskexecutor" class= "Org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor" >
< Property Name= "Corepoolsize" value= "ten"/> <property name= "maxpoolsize
" value= ""/> </bean
>
<task:annotation-driven/>
I hope this article can be helpful to everyone.