<licenses> <license> <name>Apache License, Version 2.0</name> <url>https://www.apache.org/licenses/LICENSE-2.0</url> <comments> Copyright 2011 the original author or authors.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. </comments> </license> </licenses>
Inversion Of Control:从需要依赖关系的类中获取Control,并将框架控制权交给Spring
IOC Container
Application Context:创建和管理所有Bean的上下文。典型的IOC容器。
Beans
What are the beans? @Component
What are the dependencies of a bean? @Autowired
Where to search for beans? SpringApplication
Features:
Singleton: One instance per Spring Context
Prototype: New bean whenever requested @Scope("prototype")/ @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
request: One bean per HTTP request
session: One bean per HTTP session
@Primary
If you have two components on the class path of the same type then use @Primary.
// It also decides which Algo to use. private SortAlgorithm bubbleSortAlgorithm; // However, if quickSortAlgorithm is marked as @Primary, then @Primary has higher priority.
@Qualifier
Use @Qualifier(“name”) to name and choose the algo you want to use.
However, use name is much clearer than use @Qualifier. @Qualifier is more likely a rename tool.
Constructor/Setter Injection
All mandatory(necessary) dependencies should be autowired using Constructor Injection. Other(Optional) was recommended to use Setter Injection.
Modularity of Spring
One of the important things about Spring is that it’s not one big framework. Spring is built in a very modular way. It enables you to use specific models.
Why Spring popular
With porperly usage of Dependency Injection, we are able to write test unit easily.
No plumbing(not core) code. 在内部写好了许多Exceptions,使用Spring的程序员几乎不需要自己写Exception Handling。
Modularity.(Flexible to other framework)
Stay up with the trends. like Spring Cloud.
Eclipse Skill
<Ctrl+Space> Auto Completion <Ctrl+1> File Operation <C-S-L> List Shortcuts <C-S-R> Resource Finding <C-S-T> Type Finding F3 Goto Declaration F4 Type Hierarchy <A-S-S> Code Generation
Maven
Convention over Configuration mvn compile: Compile source files mvn test compilemvn clean: Delete target directorymvn test: Run unit testsmvn package: Create a jarmvn help:effective-pommvn dependency:tree`