Spring Common annotation Rollup _java

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.