01 | Spring课程介绍
02 | 一起认识Spring家族的主要成员
03 | 跟着Spring了解技术趋势
了解 Kotlin。
WebFlux 全面落地尚需时日。
Velocity不维护了,过时的框架。
在判断是否该使用这个框架,或者技术是,可以了解下它的社区和使用人群,是否活跃等。
04 | 编写你的第一个Spring程序
@SpringBootApplication
@RestController
public class HelloSpringApplication {
public static void main(String[] args) {
SpringApplication.run(HelloSpringApplication.class, args);
}
@RequestMapping("/hello")
public String hello() {
return "Hello Spring!";
}
}
# 访问接口
curl localhost:8080/hello
# 访问健康检查
curl localhost:8080/actuator/health
打包:
mvn clean package
源包:不包含依赖 , 完整包:包含所有依赖,可直接运行
maven的install和package的区别:
package可以理解成简单的打包,而install除了打包还会把这个包安装到maven仓库中去。
运行携带依赖的jar包: java -jar hello-spring-0.0.1-SNAPSHOT.jar
maven dependencies与dependencyManagement的区别
-
dependencies即使在子项目中不写该依赖项,那么子项目仍然会从父项目中继承该依赖项(全部继承)
- dependencyManagement里只是声明依赖,并不实现引入,因此子项目需要显示的声明需要用的依赖。如果不在子项目中声明依赖,是不会从父项目中继承下来的;只有在子项目中写了该依赖项,并且没有指定具体版本,才会从父项目中继承该项,并且version和scope都读取自父pom;另外如果子项目中指定了版本号,那么会使用子项目中指定的jar版本。
<!-- 如果项目需要有自己的parent,不能使用spring-boot作为parent,则使用dependencyManagement的方式注入spring-boot依赖 -->
<!--
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.1.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
-->
<!-- 如果项目需要有自己的parent,不能使用spring-boot作为parent,指定mvn打包是在调用spring-boot:repackage时才介入 -->
<!-- <build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.3.1.RELEASE</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
-->
相关代码:
https://github.com/wuguokai/Spring-Advance/tree/master/hello-spring