Spring @ annotations

Source: Internet
Author: User

1, @controller Controller (injection service) 2, @service service (injection dao) 3, @repository dao (implement dao access) 4, @component (the normal Pojo is instantiated into the spring container, equivalent to the configuration file <bean id= "" class= ""/>)
@Component, @Service, @Controller, @Repository Annotated classes, and incorporate these classes into the spring container for Management. 
the Following is a scan component that introduces component
<context:component-scan base-package= "com.mmnc" >

where Base-package is the package that needs to be scanned (with all child packages)
1, @Service for labeling business layer components
2. @Controller for labeling Control-layer components (such as action in Struts)
3. @Repository is used to label data Access components, DAO Components.
4, @Component Refer to the components, when the component is not good to classify, we can use this annotation for labeling.
@Service public class Userserviceimpl implements UserService {}
the default name for the @Repository public class Userdaoimpl implements Userdao {} Getbean is the class name (lowercase letters), and if you want to customize it, you can specify it @service ("* * *"), This bean is a singleton by default, and if you want to change it, you can use @service ("beanname")
@Scope ("prototype") to Change. You can specify the initialization method and the destruction method (method name Arbitrary) by using the following method: @PostConstruct public void init () {}

Spring @ annotations

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.