Java day 6 Spring Annotation and others

Source: Internet
Author: User

AnnotationIs a special metadata syntax in Java. Spring supports annotation for Object Instantiation and assembly.

Use Annotation to add the context namespace (yellow part) to the Spring configuration xml ):

                   

Add the <context: annotation-config/> node at the same time. In this way, the AutowiredAnnotationBeanPostProcessor, CommonAnnotationBeanPostProcessor, PersistenceAnnotationBeanPostProcessor, and RequiredAnnotationBeanPostProcessor

Postprocessor: "processor" after bean Initialization is complete"

@ Autowired can be written in any method

A) by type by default
B) If you want to use byName, use @ Qulifier
C) Written in private field (the third injection form) (it is not recommended to destroy encapsulation)
D) if it is written on set, @ qualifier must be written on the parameter.

@ Required
Must be specified in the configuration file and injected during initialization

@ Resource
Use JSR 250, default byName
A) jar package: common-annotations.jar
B) The default value is byName and then byType.
C) You can specify a specific name.
D) recommended

Annotation indicates bean

Add <context: component-scan base-package ="Package. scan. root"/>

@ Component, @ Service, @ Repository, @ Controller is initialized to an object during ApplicationContext instantiation (corresponding to the bean in the configuration file)

A) The initialization name is the first letter of the class name in lowercase by default.
B) You can specify the name of the bean to be initialized.

@ Scope
Singleton (default) and prototype

@ PostConstruct @ PreDestory
Corresponds to the init-method and destroy-method of the configuration file bean. Construction and initialization Methods

Background Knowledge

1. JSR-Java Specification Request
A formal request to add a standardized technical specification to JCP (Java Community Process. Anyone can submit a JSR to add new APIs and services to the Java platform. JSR has become an important standard in the Java field.

2. The JSR 250
Common Annotations for the JavaTM Platform https://jcp.org/en/jsr/detail? Id = 250

3. JCP
JCP-Java Community Process, an open international organization mainly composed of Java developers and authorized persons. Its function is to develop and update.

 

Tips

1. Lock Eclipse to the taskbar
Add the following two lines to the Eclipse. ini file-vmargs In the eclipse directory:
-Vm
C: \ jdk1.7.0 _ 45 \ bin

2. Enhanced Eclipse Smart Tips:
Open the menu Windows --> Preferences --> Java --> Editor --> Code Assist, and enter the value in the Auto activation triggers for Java column:. Inputting these letters can trigger smart prompts to increase productivity.

 

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.