赞
踩
创建POM
因为是3.0.0-M1版本,是程碑版本,不是正式发布版,需要从Spring提的Maven仓库中才能下载到3.0.0-M1版本的依赖包,需要在pom.xml件中单独指定仓库地址。
如果使的是正式版,是不需要加下这段配置的
<!-- jar包的仓库地址--> <repositories> ? ? ? ?<repository> ? ? ? ? ? ?<id>spring-snapshots</id> ? ? ? ? ? ?<url>https://repo.spring.io/snapshot</url> ? ? ? ? ? ?<snapshots><enabled>true</enabled></snapshots> ? ? ? ?</repository> ? ? ? ?<repository> ? ? ? ? ? ?<id>spring-milestones</id> ? ? ? ? ? ?<url>https://repo.spring.io/milestone</url> ? ? ? ?</repository> ? ?</repositories> <!-- maven插件的仓库地址 --> ? ?<pluginRepositories> ? ? ? ?<pluginRepository> ? ? ? ? ? ?<id>spring-snapshots</id> ? ? ? ? ? ?<url>https://repo.spring.io/snapshot</url> ? ? ? ?</pluginRepository> ? ? ? ?<pluginRepository> ? ? ? ? ? ?<id>spring-milestones</id> ? ? ? ? ? ?<url>https://repo.spring.io/milestone</url> ? ? ? ?</pluginRepository> ? ?</pluginRepositories>
另外还要在pom.xml件中,添加Spring Boot所提供的pom.xml。
<parent>
? ? ? ?<groupId>org.springframework.boot</groupId>
? ? ? ?<artifactId>spring-boot-starter-parent</artifactId>
? ? ? ?<version>3.0.0-M1</version>
? ?</parent>
关于这个parent的作,后续课程中会介绍。
添加依赖
最后添加个开发web应的starter依赖
<dependencies>
? ?<dependency>
? ? ? ?<groupId>org.springframework.boot</groupId>
? ? ? ?<artifactId>spring-boot-starter-web</artifactId>
? ?</dependency>
</dependencies>
写代码
在写代码之前,请注意,我现在的JDK8,也许你也是。
创建个类,类名随便取,我的叫MyApplication,包路径为com.zhouyu
package com.zhouyu; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @RestController @EnableAutoConfiguration public class MyApplication { ? ?@RequestMapping("/") ? ?String home() { ? ? ? ?return "Hello World!"; ? } ? ?public static void main(String[] args) { ? ? ? ?SpringApplication.run(MyApplication.class, args); ? } }
然后,运main法。
我这报错了:
因为Spring Boot 3的是Spring 6,Spring 6需要JDK17。
所以,我们要在IDEA中配上JDK17,JDk17的安装没什么特殊的,和JDK8的安装样,就不在笔记浪费篇幅了。
上JDK17之后,再次运main法,就能正常启动我们的第个Spring Boot应程序了,并且会看到如下志:
"C:Program FilesJavajdk-17.0.1injava.exe" "-javaagent:C:Program FilesJetBrainsIntelliJ IDEA 2021.1.3libidea_rt.jar=64855:C:Program FilesJetBrainsIntelliJ IDEA 2021.1.3in" -Dfile.encoding=UTF-8 - classpath D:IdeaProjectsZhouyuSpringBootTeacher argetclasses;C:Userszhouyu.m2 epositoryorgspringframework ootspring-boot-starter-web.0.0-M1spring-boot-starter-web-3.0.0- M1.jar;C:Userszhouyu.m2 epositoryorgspringframeworkootspringboot-starter.0.0-M1spring-boot-starter-3.0.0- M1.jar;C:Userszhouyu.m2 epositoryorgspringframeworkootspringboot.0.0-M1spring-boot-3.0.0- M1.jar;C:Userszhouyu.m2 epositoryorgspringframeworkootspringboot-autoconfigure.0.0-M1spring-boot-autoconfigure-3.0.0- M1.jar;C:Userszhouyu.m2 epositoryorgspringframeworkootspringboot-starter-logging.0.0-M1spring-boot-starter-logging-3.0.0- M1.jar;C:Userszhouyu.m2 epositorychqoslogbacklogbackclassic.2.10logback-classic1.2.10.jar;C:Userszhouyu.m2 epositorychqoslogbacklogbackcore.2.10logback-core1.2.10.jar;C:Userszhouyu.m2 epositoryorgslf4jslf4japi.7.33slf4j-api1.7.33.jar;C:Userszhouyu.m2 epositoryorgapachelogginglog4jlog4jto-slf4j.17.1log4j-to-slf4j2.17.1.jar;C:Userszhouyu.m2 epositoryorgapachelogginglog4jlog4japi.17.1log4j-api2.17.1.jar;C:Userszhouyu.m2 epositoryorgslf4jjul-toslf4j.7.33jul-to-slf4j1.7.33.jar;C:Userszhouyu.m2 epositoryjakartaannotationjakarta.anno tation-api.0.0jakarta.annotation-api2.0.0.jar;C:Userszhouyu.m2 epositoryorgspringframeworkspringcore.0.0-M2spring-core-6.0.0- M2.jar;C:Userszhouyu.m2 epositoryorgspringframeworkspringjcl.0.0-M2spring-jcl-6.0.0- M2.jar;C:Userszhouyu.m2 epositoryorgyamlsnakeyaml.30snakeyaml1.30.jar;C:Userszhouyu.m2 epositoryorgspringframeworkootspringboot-starter-json.0.0-M1spring-boot-starter-json-3.0.0- M1.jar;C:Userszhouyu.m2 epositorycomasterxmljacksoncorejacksondatabind.13.1jackson-databind2.13.1.jar;C:Userszhouyu.m2 epositorycomasterxmljacksoncorejack son-annotations.13.1jackson-annotations2.13.1.jar;C:Userszhouyu.m2 epositorycomasterxmljacksoncorejack son-core.13.1jackson-core2.13.1.jar;C:Userszhouyu.m2 epositorycomasterxmljacksondatatype
jackson-datatype-jdk8.13.1jackson-datatype-jdk8-
2.13.1.jar;C:Userszhouyu.m2
epositorycom asterxmljacksondatatype
jackson-datatype-jsr310.13.1jackson-datatype-jsr310-
16
2.13.1.jar;C:Userszhouyu.m2
epositorycom asterxmljacksonmoduleja
ckson-module-parameter-names.13.1jackson-module-parameter-names2.13.1.jar;C:Userszhouyu.m2
epositoryorgspringframeworkootspring
-boot-starter-tomcat.0.0-M1spring-boot-starter-tomcat-3.0.0-
M1.jar;C:Userszhouyu.m2
epositoryorgapache omcatembed omcatembed-core.0.16 omcat-embed-core10.0.16.jar;C:Userszhouyu.m2
epositoryorgapache omcatembed omcat
-embed-el.0.16 omcat-embed-el10.0.16.jar;C:Userszhouyu.m2
epositoryorgapache omcatembed omcat
-embed-websocket.0.16 omcat-embed-websocket10.0.16.jar;C:Userszhouyu.m2
epositoryorgspringframeworkspringweb.0.0-M2spring-web-6.0.0-
M2.jar;C:Userszhouyu.m2
epositoryorgspringframeworkspringbeans.0.0-M2spring-beans-6.0.0-
M2.jar;C:Userszhouyu.m2
epositoryorgspringframeworkspringwebmvc.0.0-M2spring-webmvc-6.0.0-
M2.jar;C:Userszhouyu.m2
epositoryorgspringframeworkspringaop.0.0-M2spring-aop-6.0.0-
M2.jar;C:Userszhouyu.m2
epositoryorgspringframeworkspringcontext.0.0-M2spring-context-6.0.0-
M2.jar;C:Userszhouyu.m2
epositoryorgspringframeworkspringexpression.0.0-M2spring-expression-6.0.0-M2.jar
com.zhouyu.MyApplication
. ? ____ ? ? ? ? ?_ ? ? ? ? ? ?__ _ _
/\ / ’ __ _ () __ __ _
( ( )__ | '_ | ‘| | ’ / ` |
/ ?)| |)| | | | | || (| | ) ) ) )
?’ || .__|| ||| |, | / / / /
=========||==============|/=///_/
:: Spring Boot :: ? ? ? ? ? ? (v3.0.0-M1)
2022-03-16 20:43:21.849 ?INFO 17520 — [ ? ? ? ? ? main]
com.zhouyu.MyApplication ? ? ? ? ? ? ? ? : Starting MyApplication using
Java 17.0.1 on DESKTOP-P9KHN97 with PID 17520
(D:IdeaProjectsZhouyuSpringBoot-Teacher argetclasses started by
zhouyu in D:IdeaProjectsZhouyuSpringBoot-Teacher)
2022-03-16 20:43:21.852 ?INFO 17520 — [ ? ? ? ? ? main]
com.zhouyu.MyApplication ? ? ? ? ? ? ? ? : No active profile set, falling
back to default profiles: default
2022-03-16 20:43:23.257 ?INFO 17520 — [ ? ? ? ? ? main]
o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with
port(s): 8080 (http)
2022-03-16 20:43:23.271 ?INFO 17520 — [ ? ? ? ? ? main]
o.apache.catalina.core.StandardService ? : Starting service [Tomcat]
2022-03-16 20:43:23.272 ?INFO 17520 — [ ? ? ? ? ? main]
org.apache.catalina.core.StandardEngine : Starting Servlet engine:
[Apache Tomcat/10.0.16]
2022-03-16 20:43:23.406 ?INFO 17520 — [ ? ? ? ? ? main] o.a.c.c.C.
[Tomcat].[localhost].[/] ? ? ? : Initializing Spring embedded
WebApplicationContext
2022-03-16 20:43:23.409 ?INFO 17520 — [ ? ? ? ? ? main
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。