Notes for Spring

Source: Internet
Author: User

Notes for Spring

Annotations on classes (annotations to the spring container are given by JavaBean)

If the annotations have no parameters, the default is the class name, if any. The bean's name is the parameter value

    1. @component The most primitive annotations will be javabean to the spring container
    2. @service give the Service (business) layer class to the Spring container management
    3. @repository give the DAO layer class to the Spring container management
    4. @controller give the class of the control layer to the Spring container management
Annotations on properties (annotations that assign values (initialization) to properties in a class)
  1. @value ("") is required for the base data type (including string) assignment parameter
  2. @AutoWrited [("parameter")] is the reference data assignment, the spring container will find the corresponding type, if the container has more than one type of value, need to pass parameters, spring container According to the name of the parameter to find the corresponding instance object, you can also use @quailfier ("") Annotation parameters Specify JavaBean
  3. @Resource [(name=" ")] assigns a value to the reference data, and if spring is a collection data type, it needs to be used with the <util> property.

    ① if both name and type are specified, The only matching bean from the spring context is found to be assembled, and an exception is thrown if it is not found.

    ② if name is specified, The matching bean that looks for the name (ID) from the context is assembled, and an exception is thrown if it is not found.

    ③ if type is specified, A unique bean similar to a match is found in the context, and an exception is thrown if it is not found or multiple.

    ④ If neither name is specified, If no type is specified, it is automatically assembled according to ByName, and if there is no match, the fallback is a match for the original type and is automatically assembled if matched.

  4. @Bean use XP with @configeuration for adding factory methods to spring containers:

Public person Getperson (return new person)

Equivalent to configuring <bean id= "Getperson" class= com.xxx "in Bean.xml. Person "/>

other Annotations
    1. @scope ("") specifies the scope for the bean: Request,session,singleton,prototype
    2. @PostConstruct function on the method, specify the initialization method for the bean
    3. @Perdestroy function on the method, specifying the method of destruction for the bean, only effective at Scope=singleton

Notes for Spring

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.