SpringBoot学习笔记
注意:本篇博客是参考了github上的SpringAll项目进行学习
附上github项目地址:https://github.com/wuyouzhuguli/SpringAll(作者打钱)
开始SpringBoot
进入Spring官网:https://start.spring.io/

红框处可以选择额外的依赖dependencies
导入项目后的目录结构

target目录是运行Maven后由Maven创建的,默认打包的位置也在target目录下
记录坑点:SpringBoot默认扫描子包下的类。即com.Lirs.Spring.XXX包的类才会被扫描。
当初干过的蠢事:将controller包放在于SpringBoot同级包下,导致访问页面404,原因,SpringBoot没有扫描controller包下的Controller类,导致注解无效。
关于pom.xml

spring-boot-starter-parent指定了这是一个SpringBoot项目,parent中有许多默认Maven依赖,可以在配置的maven仓库 repository\org\springframework\boot\spring-boot-dependencies\版本号下的spring-boot-denpendencies-版本号中查看

需要注意的是:并非所有默认的依赖都会被加载,只有当项目中有对应的start时,才会被加载进来。
比如:

spring-boot-starter-web默认集成了tomcat,所以我们不需要再为项目配置tomcat
如果不想使用tomcat,可以在pom.xml中排除tomcat,再引入自己需要的依赖
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- 这里排除了tomcat依赖,引入了jetty -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jetty</artifactId>
</dependency>
</dependencies>
还可以在pom.xml中指定某个依赖的版本
<properties>
<tomcat.version>7.0.72</tomcat.version>
</properties>

这里我指定tomcat的版本为7.0.72 默认版本是9.0.27,添加后maven就为我安装了7.0.72的tomcat依赖
-
spring-boot-maven-plugin为Spring Boot Maven 插件 提供了:
把项目打包成一个可以执行的超级JAR(uber-Jar),将项目中所有的依赖都加入到jar包中,并为jar包添加一个描述文件,其中的内容可以让java -jar来运行项目
-
搜索public staitc void main()方法来标记运行类
猜测:

应该描述文件是maven-status\maven-compiler-plugin\compile\default-complie下的createdFiles.lst和inputFiles.lst中的一个或两个
两个文件的内容:
inputFiles.lst : E:\框架学习源码\Spring\src\main\java\com\Lirs\Spring\Application.java(main方法入口?)
createdFiles.lst : com\Lirs\Spring\Application.class(可运行的class文件?)
本文是SpringBoot学习笔记,通过Spring官网和SpringAll项目进行学习。介绍了SpringBoot项目创建、依赖选择、pom.xml配置,强调了SpringBoot默认扫描子包下的类,以及spring-boot-starter-parent在项目中的作用。同时讲解了如何排除和指定依赖版本,如tomcat,以及spring-boot-maven-plugin的作用。
937

被折叠的 条评论
为什么被折叠?



