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.