(一)Spring官网
Spring Framework - Spring Framework
目前(2022-5-27)Spring Framework版本是5.3.20
(二)Spring框架优点
Spring makes Java productive.
Spring makes Java reactive.
Spring makes Java cloud-ready.
Spring makes Java simple.
Spring makes Java modern.
(三)为什么要选择Spring?
Spring makes programming Java quicker, easier, and safer for everybody. Spring’s focus on speed, simplicity, and productivity has made it the world's most popular Java framework.
“We use a lot of the tools that come with the Spring framework and reap the benefits of having a lot of the out of the box solutions, and not having to worry about writing a ton of additional code—so that really saves us some time and energy.” —— SEAN GRAHAM, APPLICATION TRANSFORMATION LEAD, DICK’S SPORTING GOODS
访问迪克体育用品网站:https://www.dickssportinggoods.com
-
Spring框架有两个非常重要的特性:IoC(Inversion of Control - 控制反转)和AOP(Aspect-Oriented Programming - 面向切面编程)。
-
Spring容器其实就是一个Bean工厂,在工厂里通过配置文件或配置类创建各种各样的Bean,然后在Spring应用程序就可以按照名称或类型获取工厂里已经配置好的Bean。下面我们就通过一个具体的案例来了解Spring容器是如何工作的。
(二)创建Maven项目
- 创建Maven项目 -
SpringDemo
,设置项目位置以及组ID
单击【Finish】按钮
修改项目的Maven配置
(三)添加Spring依赖
-
在Maven仓库里查找Spring框架(https://mvnrepository.com)
查看Spring Core
选择最新版本 - 5.3.20
添加到pom.xml
文件的<dependencies>
元素里
-
同理添加其他依赖
-
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion><groupId>net.huawei.spring</groupId>
<artifactId>SpringDemo</artifactId>
<version>1.0-SNAPSHOT</version><dependencies>
<!--Spring核心-->
<dependency>
<groupId>org.springframework</groupId>