Java(84):从Spring boot官网创建Spring boot Demo项目

因idea社区版本2020.2版本,无法在idea工具中创建Spring-boot项目,所以从官网模拟创建一个项目。

1、在Spring官网创建一个Spring boot的Demo项目

Spring initializr

https://start.spring.io/

https://spring.io/quickstart

start.spring.io创建"Web"项目。在"依赖项"对话框中,搜索并添加"Web"依赖项,如下图所示。点击"生成"按钮,下载demo.zip,然后将其解压缩。

 2、Idea运行Demo项目

2.1、Idea打开demo项目

2.2、配置好maven环境

2.3、添加上版本号,右侧点击maven引用,下载相关插件

 

3、添加代码并执行

3.1、根据https://spring.io/quickstart的示例代码,添加到DemoApplication.java中

package com.example.demo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@SpringBootApplication
public class DemoApplication {

	public static void main(String[] args) {
		SpringApplication.run(DemoApplication.class, args);
	}

	@GetMapping("/hello")
	public String hello(@RequestParam(value = "name", defaultValue = "World") String name) {
		return String.format("Hello %s!", name);
	}

}

3.2、Windows窗口:mvnw spring-boot:run

4、浏览器访问:​​​​​​http://localhost:8080/hello

 指导文档:

https://spring.io/quickstart

执行过程:

Starting DemoApplication using Java 1.8.0_211

Starting Servlet engine: [Apache Tomcat/9.0.58]

D:\java_project2022\demo>mvnw spring-boot:run
[INFO] Scanning for projects...
[INFO]
[INFO] --------------------------< com.example:demo >--------------------------
[INFO] Building demo 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] >>> spring-boot-maven-plugin:2.6.4:run (default-cli) > test-compile @ demo >>>
[INFO]
[INFO] --- maven-resources-plugin:3.2.0:resources (default-resources) @ demo ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Using 'UTF-8' encoding to copy filtered properties files.
[INFO] Copying 1 resource
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ demo ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to D:\java_project2022\demo\target\classes
[INFO]
[INFO] --- maven-resources-plugin:3.2.0:testResources (default-testResources) @ demo ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Using 'UTF-8' encoding to copy filtered properties files.
[INFO] skip non existing resourceDirectory D:\java_project2022\demo\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:testCompile (default-testCompile) @ demo ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to D:\java_project2022\demo\target\test-classes
[INFO]
[INFO] <<< spring-boot-maven-plugin:2.6.4:run (default-cli) < test-compile @ demo <<<
[INFO]
[INFO]
[INFO] --- spring-boot-maven-plugin:2.6.4:run (default-cli) @ demo ---
[INFO] Attaching agents: []

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::                (v2.6.4)

2022-03-13 20:06:47.377  INFO 20400 --- [           main] com.example.demo.DemoApplication         : Starting DemoApplication using Java 1.8.0_211 on LAPTOP-HPR7S7MP with PID 20400 (D:
\java_project2022\demo\target\classes started by HMF in D:\java_project2022\demo)
2022-03-13 20:06:47.379  INFO 20400 --- [           main] com.example.demo.DemoApplication         : No active profile set, falling back to 1 default profile: "default"
2022-03-13 20:06:48.137  INFO 20400 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2022-03-13 20:06:48.146  INFO 20400 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2022-03-13 20:06:48.146  INFO 20400 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.58]
2022-03-13 20:06:48.190  INFO 20400 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2022-03-13 20:06:48.190  INFO 20400 --- [           main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 776 ms
2022-03-13 20:06:48.387  INFO 20400 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''
2022-03-13 20:06:48.393  INFO 20400 --- [           main] com.example.demo.DemoApplication         : Started DemoApplication in 1.229 seconds (JVM running for 1.474)
2022-03-13 20:07:12.851  INFO 20400 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring DispatcherServlet 'dispatcherServlet'
2022-03-13 20:07:12.852  INFO 20400 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : Initializing Servlet 'dispatcherServlet'
2022-03-13 20:07:12.853  INFO 20400 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : Completed initialization in 1 ms

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

宁儿数据安全

您的鼓励是我创作的动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值