第一点:在学习SpringBoot框架前要具备下面的知识.
- 1 学过java的基础课程 java的基础课程 面向对象,异常处理,存储方式,JDBC,文件的上转下载。
2 学过Jsp和Service的编程 了解Service的几个重要的对象 了解Service的生命周期
九大内置对象 四大作用域 El 核心标签库
3 学过前端的一些内容 HTML CSS CSS3 JavaScript Jquery Ajax Json
4 学过SSM框架中的三个基本框架的操作 SpringMvc Spring MyBatis 并且在脑子中有非常清晰的三层架构的流程图
学过之前的 SpringMvc Spring MyBatis
5 在此之前学过Maven这项技术 会在命令窗口构建Maven的项目 web项目 生命周期 依赖的关系 理解约定大于配置的关键
会配置maven的各种环境
上面只是大致的内容
第二点:Spring Boot是由Pivotal团队提供的全新框架,其设计目的是用来简化新Spring应用的初始搭建以及开发过程.
Spring Boot是由Pivotal团队提供的全新框架,其设计目的是用来简化新Spring应用的初始搭建以及开发过程。
该框架使用了特定的方式来进行配置,从而使开发人员不再需要定义样板化的配置。
通过这种方式,Spring Boot致力于在蓬勃发展的快速应用开发领域(rapid application development)成为领导者。
第三点:SpringBoot百度官网.
https://baike.baidu.com/item/Spring%20Boot/20249767?fr=aladdin
SpringBoot基于Spring4.0设计,不仅继承了Spring框架原有的优秀特性,
而且还通过简化配置来进一步简化了Spring应用的整个搭建和开发过程。
另外SpringBoot通过集成大量的框架使得依赖包的版本冲突,以及引用的不稳定性等问题得到了很好的解决。
第四点 SpringBoot所具备的特征有
(1)可以创建独立的Spring应用程序,并且基于其Maven或Gradle插件,可以创建可执行的JARs和WARs;
(2)内嵌Tomcat或Jetty等Servlet容器;
(3)提供自动配置的“starter”项目对象模型(POMS)以简化Maven配置;
(4)尽可能自动配置Spring容器;
(5)提供准备好的特性,如指标、健康检查和外部化配置;
(6)绝对没有代码生成,不需要XML配置。
第五点 了解两个官网.
SpringBoot官网:https://spring.io/
Maven的官网:
https://mvnrepository.com/artifact/javax.servlet
/javax.servlet-api/4.0.1?__cf_chl_tk
=CeJqhhBtdUnKrkCSrIRShKxBXWtkk0dgVCzpyhEdv.U-1662186144-0-gaNycGzNCmU
第六点 为什么要学习SpringBoot框架.
具体整理一下 Spring Boot 的优点有
1、自动配置
2、依赖管理变得简单
3、内置 Tomcat、Jetty 容器
第七部分:Spring官网的学习:https://spring.io/
@1 方式一创建Springboot项目 在官网上创建 初学者不建议用方案一
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.7.3</version> <relativePath/> <!-- lookup parent from repository --> </parent> <groupId>com.example</groupId> <artifactId>demo</artifactId> <version>0.0.1-SNAPSHOT</version> <name>demo</name> <description>Demo project for Spring Boot</description> <properties> <java.version>17</java.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project>
@2 利用Idea软件创建我的第一个SpringBoot程序。
前期的预备工作 自己电脑上必须有以下设置:
Java中的Jdk Maven的环境配置完整 有自己的本地仓库 请看下面的图示
</proxies> < <profile> <id>jdk-1.4</id> <activation> <jdk>1.4</jdk> </activation> <repositories> <repository> <id>jdk14</id> <name>Repository for JDK 1.4 builds</name> <url>http://www.myhost.com/maven/jdk14</url> <layout>default</layout> <snapshotPolicy>always</snapshotPolicy> </repository> </repositories> </profile> --> <profile> <id>jdk-1.8</id> <activation> <activeByDefault>true</activeByDefault> <jdk>1.8</jdk> </activation> <properties> <maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.target>1.8</maven.compiler.target> <maver.compiler.compilerVersion>1.8</maver.compiler.compilerVersion> </properties> </profile> </profiles> <!-- activeProfiles | List of profiles that are active for all builds. | <activeProfiles> <activeProfile>alwaysActiveProfile</activeProfile> <activeProfile>anotherAlwaysActiveProfile</activeProfile> </activeProfiles> --> </settings>
测试判断环境的配置是否成功
C:\Users\MZFAITHDREAM>java -version java version "1.8.0_171" Java(TM) SE Runtime Environment (build 1.8.0_171-b11) Java HotSpot(TM) 64-Bit Server VM (build 25.171-b11, mixed mode) C:\Users\MZFAITHDREAM>mvn [INFO] Scanning for projects... [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Total time: 0.123 s [INFO] Finished at: 2022-09-03T20:00:15+08:00 [INFO] ------------------------------------------------------------------------ [ERROR] No goals have been specified for this build. You must specify a valid lifecycle phase or a goal in the format <plugin-prefix>:<goal> or <plugin-group-id>:<plugin-artifact-id>[:<plugin-version>]:<goal>. Available lifecycle phases are: validate, initialize, generate-sources, process-sources, generate-resources, process-resources, compile, process-classes, generate-test-sources, process-test-sources, generate-test-resources, process-test-resources, test-compile, process-test-classes, test, prepare-package, package, pre-integration-test, integration-test, post-integration-test, verify, install, deploy, pre-clean, clean, post-clean, pre-site, site, post-site, site-deploy. -> [Help 1] [ERROR] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. [ERROR] Re-run Maven using the -X switch to enable full debug logging. [ERROR] [ERROR] For more information about the errors and possible solutions, please read the following articles: [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/NoGoalSpecifiedException C:\Users\MZFAITHDREAM>mvn -v Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f) Maven home: D:\softwhy\apache-maven-3.6.3\bin\.. Java version: 1.8.0_171, vendor: Oracle Corporation, runtime: C:\Program Files\Java\jre1.8.0_171 Default locale: zh_CN, platform encoding: GBK OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows" C:\Users\MZFAITHDREAM>
环境配置完成后接下来创建Idea的第一个SpringBoot程序:
<?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>hellowoeld</groupId> <artifactId>com.java.springboot</artifactId> <version>1.0-SNAPSHOT</version> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.7.3</version> <relativePath/> <!-- lookup parent from repository --> </parent> <dependencies> <!--开发web应用的架包--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> </dependencies> </project>
package com.java.controller.com.java; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; // @Controller+@ResponseBody //http://localhost:8080/A/a //内 有服务器 @RestController @RequestMapping("/A") public class HelloController { @RequestMapping("/a") public String hello() { return "<h1 align=\"center\">不要因为懒惰,而错过本该属于你的人生。这个世界上优秀的人很多,但做不到的总有人会做到。\n" + "\n" + "\t\t\t你逃避的恐惧,但在有些人看来只是小事一桩。你偷懒不学的技能,有一天会用得上,你贪图安逸的过去,造就焦虑的当下。\n" + "\n" + "\t\t\t折腾也许很累很难,但至少不留遗憾不必四处寻找答案,-切皆在你手上。不要因\n" + "\n" + "\t\t\t为自己的懒散而错过本该属于你的人生,一定要努力向前跑,去见那些我们未曾见过的风景</h1>"; } }
package com.java.controller.com.java; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; // @Controller+@ResponseBody //http://localhost:8080/A/a //内 有服务器 @RestController @RequestMapping("/B") public class HelloController1 { @RequestMapping("/a") public String hello() { return "<h1 align=\"center\">这个世界可能很大,大到自己想走遍世界的每一个角落。" + "这个世界可以很小,小到每天算计着柴米油盐,每天都在消费钱的路上。可能这又是生活每天都在忙碌," + "在忙碌的过程忽略的人是自己。忽略了自己的珍贵。忽略了自己的感受。忽略了自己的想法。</h1>"; } }
package com.java.controller.com.java; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication //启动类 public class Application { public static void main(String[] args) { SpringApplication.run(Application.class,args); } }
"C:\Program Files\Java\jdk1.8.0_171\bin\java.exe" -XX:TieredStopAtLevel=1 -noverify -Dspring.output.ansi.enabled=always -Dcom.sun.management.jmxremote -Dspring.jmx.enabled=true -Dspring.liveBeansView.mbeanDomain -Dspring.application.admin.enabled=true "-javaagent:D:\IDEA\com.text\IntelliJ IDEA 2020.1.2\lib\idea_rt.jar=55233:D:\IDEA\com.text\IntelliJ IDEA 2020.1.2\bin" -Dfile.encoding=UTF-8 -classpath "C:\Program Files\Java\jdk1.8.0_171\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.8.0_171\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.8.0_171\jre\lib\ext\access-bridge-64.jar;C:\Program Files\Java\jdk1.8.0_171\jre\lib\ext\cldrdata.jar;C:\Program Files\Java\jdk1.8.0_171\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.8.0_171\jre\lib\ext\jaccess.jar;C:\Program Files\Java\jdk1.8.0_171\jre\lib\ext\jfxrt.jar;C:\Program Files\Java\jdk1.8.0_171\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.8.0_171\jre\lib\ext\nashorn.jar;C:\Program Files\Java\jdk1.8.0_171\jre\lib\ext\sunec.jar;C:\Program Files\Java\jdk1.8.0_171\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.8.0_171\jre\lib\ext\sunmscapi.jar;C:\Program Files\Java\jdk1.8.0_171\jre\lib\ext\sunpkcs11.jar;C:\Program Files\Java\jdk1.8.0_171\jre\lib\ext\zipfs.jar;C:\Program Files\Java\jdk1.8.0_171\jre\lib\javaws.jar;C:\Program Files\Java\jdk1.8.0_171\jre\lib\jce.jar;C:\Program Files\Java\jdk1.8.0_171\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.8.0_171\jre\lib\jfxswt.jar;C:\Program Files\Java\jdk1.8.0_171\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.8.0_171\jre\lib\management-agent.jar;C:\Program Files\Java\jdk1.8.0_171\jre\lib\plugin.jar;C:\Program Files\Java\jdk1.8.0_171\jre\lib\resources.jar;C:\Program Files\Java\jdk1.8.0_171\jre\lib\rt.jar;D:\maven-workspace\spaceVideo\com.java.springboot\target\classes;D:\maven_repository\org\springframework\boot\spring-boot-starter-web\2.7.3\spring-boot-starter-web-2.7.3.jar;D:\maven_repository\org\springframework\boot\spring-boot-starter\2.7.3\spring-boot-starter-2.7.3.jar;D:\maven_repository\org\springframework\boot\spring-boot\2.7.3\spring-boot-2.7.3.jar;D:\maven_repository\org\springframework\boot\spring-boot-autoconfigure\2.7.3\spring-boot-autoconfigure-2.7.3.jar;D:\maven_repository\org\springframework\boot\spring-boot-starter-logging\2.7.3\spring-boot-starter-logging-2.7.3.jar;D:\maven_repository\ch\qos\logback\logback-classic\1.2.11\logback-classic-1.2.11.jar;D:\maven_repository\ch\qos\logback\logback-core\1.2.11\logback-core-1.2.11.jar;D:\maven_repository\org\slf4j\slf4j-api\1.7.36\slf4j-api-1.7.36.jar;D:\maven_repository\org\apache\logging\log4j\log4j-to-slf4j\2.17.2\log4j-to-slf4j-2.17.2.jar;D:\maven_repository\org\apache\logging\log4j\log4j-api\2.17.2\log4j-api-2.17.2.jar;D:\maven_repository\org\slf4j\jul-to-slf4j\1.7.36\jul-to-slf4j-1.7.36.jar;D:\maven_repository\jakarta\annotation\jakarta.annotation-api\1.3.5\jakarta.annotation-api-1.3.5.jar;D:\maven_repository\org\springframework\spring-core\5.3.22\spring-core-5.3.22.jar;D:\maven_repository\org\springframework\spring-jcl\5.3.22\spring-jcl-5.3.22.jar;D:\maven_repository\org\yaml\snakeyaml\1.30\snakeyaml-1.30.jar;D:\maven_repository\org\springframework\boot\spring-boot-starter-json\2.7.3\spring-boot-starter-json-2.7.3.jar;D:\maven_repository\com\fasterxml\jackson\core\jackson-databind\2.13.3\jackson-databind-2.13.3.jar;D:\maven_repository\com\fasterxml\jackson\core\jackson-annotations\2.13.3\jackson-annotations-2.13.3.jar;D:\maven_repository\com\fasterxml\jackson\core\jackson-core\2.13.3\jackson-core-2.13.3.jar;D:\maven_repository\com\fasterxml\jackson\datatype\jackson-datatype-jdk8\2.13.3\jackson-datatype-jdk8-2.13.3.jar;D:\maven_repository\com\fasterxml\jackson\datatype\jackson-datatype-jsr310\2.13.3\jackson-datatype-jsr310-2.13.3.jar;D:\maven_repository\com\fasterxml\jackson\module\jackson-module-parameter-names\2.13.3\jackson-module-parameter-names-2.13.3.jar;D:\maven_repository\org\springframework\boot\spring-boot-starter-tomcat\2.7.3\spring-boot-starter-tomcat-2.7.3.jar;D:\maven_repository\org\apache\tomcat\embed\tomcat-embed-core\9.0.65\tomcat-embed-core-9.0.65.jar;D:\maven_repository\org\apache\tomcat\embed\tomcat-embed-el\9.0.65\tomcat-embed-el-9.0.65.jar;D:\maven_repository\org\apache\tomcat\embed\tomcat-embed-websocket\9.0.65\tomcat-embed-websocket-9.0.65.jar;D:\maven_repository\org\springframework\spring-web\5.3.22\spring-web-5.3.22.jar;D:\maven_repository\org\springframework\spring-beans\5.3.22\spring-beans-5.3.22.jar;D:\maven_repository\org\springframework\spring-webmvc\5.3.22\spring-webmvc-5.3.22.jar;D:\maven_repository\org\springframework\spring-aop\5.3.22\spring-aop-5.3.22.jar;D:\maven_repository\org\springframework\spring-context\5.3.22\spring-context-5.3.22.jar;D:\maven_repository\org\springframework\spring-expression\5.3.22\spring-expression-5.3.22.jar" com.java.controller.com.java.Application . ____ _ __ _ _ /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \ ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \ \\/ ___)| |_)| | | | | || (_| | ) ) ) ) ' |____| .__|_| |_|_| |_\__, | / / / / =========|_|==============|___/=/_/_/_/ :: Spring Boot :: (v2.7.3) 2022-09-03 20:08:42.239 INFO 32124 --- [ main] c.java.controller.com.java.Application : Starting Application using Java 1.8.0_171 on HELLOWWORLD with PID 32124 (D:\maven-workspace\spaceVideo\com.java.springboot\target\classes started by MZFAITHDREAM in D:\maven-workspace\spaceVideo\com.java.springboot) 2022-09-03 20:08:42.243 INFO 32124 --- [ main] c.java.controller.com.java.Application : No active profile set, falling back to 1 default profile: "default" 2022-09-03 20:08:43.767 INFO 32124 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http) 2022-09-03 20:08:43.779 INFO 32124 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat] 2022-09-03 20:08:43.780 INFO 32124 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.65] 2022-09-03 20:08:44.301 INFO 32124 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext 2022-09-03 20:08:44.301 INFO 32124 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1979 ms 2022-09-03 20:08:44.729 INFO 32124 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path '' 2022-09-03 20:08:44.736 INFO 32124 --- [ main] c.java.controller.com.java.Application : Started Application in 3.177 seconds (JVM running for 4.833)